exit code of a script that raises an Exception?

thequietcenter at gmail.com thequietcenter at gmail.com
Tue Sep 9 10:41:54 EDT 2014


On Tuesday, September 9, 2014 9:56:04 AM UTC-4, thequie... at gmail.com wrote:

> I wonder if all exceptions throw the exact same non-zero exit code, or whether a specific exit code is assigned to each exception uniquely. Or whether the exit code behavior is undefined (especially since it appears to be undocumented).
> 

Just found sys.excepthook. I see that there is no sys.exit() call in its documented behavior: https://docs.python.org/2/library/sys.html


sys.excepthook(type, value, traceback)
This function prints out a given traceback and exception to sys.stderr.

When an exception is raised and uncaught, the interpreter calls sys.excepthook with three arguments, the exception class, exception instance, and a traceback object. In an interactive session this happens just before control is returned to the prompt; in a Python program this happens just before the program exits. The handling of such top-level exceptions can be customized by assigning another three-argument function to sys.excepthook.



More information about the Python-list mailing list