The python Exception
class is supposed to be used for all user defined exceptions. Documentation also says it is used by all non-system-exiting builtin exceptions. I need to create a user defined exception that will system exit if not handled. In quick tests, calling a method (while not using try
...catch
) that raises my user defined exception doesn't cause an exit. In debugging, I can see that the exception is 'received' by the python interpreter, but it doesn't cause an exit.
CodePudding user response:
Are you sure? Exceptions do normally cause the program to exit. The following never reaches the print
statement.
class MyError(Exception):
pass
raise MyError
print("survived")
If you see different results, it must be because you are doing something else. Add your code to your question if you still can't see what you are doing wrong.