-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve error reporting #209
Comments
Thanks for your pull request. |
Yes, what you describe sounds good. I agree that in the executable Python script it is nicer to catch the exception and print just an error message (and not use the default exception handler that prints the stack trace).
You don't need to use |
Is it possible to build a custom exception which I can raise, but which does not print the stack trace when raising it? I did some testing but did not manage to built such a exception. |
You only get a stack trace if you don't catch the exception and it is caught by the default exception handler. If you catch the exception in your main function and print the message and exit then no stack trace will be printed. |
That is correct. I only wonder how I can exit after catching the exception without calling sys.exit()? If I understand you correctly you want to avoid using sys.exit(). |
Calling sys.exit() in the executable script (such as To be safe, you can completely avoid |
While working on fixing some issues related to setting license files (#208), I've noticed that errors are not handled very consistently throughout the code base. It would be nice to consistently use exceptions for reporting errors from functions.
Currently, some places
exit()
is called to signal errors. This is not good because it makes it impossible to call the Python function from an application, because callingexit()
immedately crashes the entire application.At some other places, complex return values are used. For example, error code and error text. This is not ideal either, because it makes the code too complicated and fragile (you need to make sure that the list items that are returned matches the expected list items everywhere where the function is used).
Instead, you can define your own exception type that stores everything that you need, such error code, text displayable to the user. The exception can be caught in the executable scripts or you can just let Python's default exception handler deal with the issue (print the stack trace and quit the process with error status).
The text was updated successfully, but these errors were encountered: