Python Forum
name of exception for exit() - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: name of exception for exit() (/thread-18621.html)



name of exception for exit() - Skaperen - May-24-2019

when exit() is called, it's really raising a special exception that does not dump anything. i'd like to capture this exception but i can't find its name. since there is no stack dump, i can't see what it raises by just doing one. anyone got the name for this (and, if needed, what module it's in)?


RE: name of exception for exit() - Yoriz - May-24-2019

https://docs.python.org/3/library/exceptions.html#SystemExit Wrote:exception SystemExit
This exception is raised by the sys.exit() function. It inherits from BaseException instead of Exception so that it is not accidentally caught by code that catches Exception. This allows the exception to properly propagate up and cause the interpreter to exit. When it is not handled, the Python interpreter exits; no stack traceback is printed. The constructor accepts the same optional argument passed to sys.exit(). If the value is an integer, it specifies the system exit status (passed to C’s exit() function); if it is None, the exit status is zero; if it has another type (such as a string), the object’s value is printed and the exit status is one.

A call to sys.exit() is translated into an exception so that clean-up handlers (finally clauses of try statements) can be executed, and so that a debugger can execute a script without running the risk of losing control. The os._exit() function can be used if it is absolutely positively necessary to exit immediately (for example, in the child process after a call to os.fork()).

code
The exit status or error message that is passed to the constructor. (Defaults to None.)



RE: name of exception for exit() - Skaperen - May-24-2019

the way exit() handles a string can eliminate a few lines of my code that was trying to do the same thing with return.