Use exception to replace int return type