exit code of a script that raises an Exception?

Ned Batchelder ned at nedbatchelder.com
Tue Sep 9 17:22:05 CEST 2014


On 9/9/14 9:55 AM, thequietcenter at gmail.com wrote:
> Hello, after looking at the docs for Exception:
> https://docs.python.org/2/library/exceptions.html
>
> I do not see any information on the guaranteed exit code a script that exits because Python threw an exception.
>
> 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).
>
> Thanks,
> Terrence
>

A quick check demonstrates that exceptions do not get distinct status 
codes.  BTW: how could they?, you can create new exception types, there 
is not a bounded number of them.

On my Mac, Python 2.7 exited with a status code of 1 for 
ZeroDivisionError, NameError, SyntaxError, IndexError, and KeyError.

-- 
Ned Batchelder, http://nedbatchelder.com




More information about the Python-list mailing list