Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77728 > unrolled thread
| Started by | thequietcenter@gmail.com |
|---|---|
| First post | 2014-09-09 06:55 -0700 |
| Last post | 2014-09-09 11:22 -0400 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
exit code of a script that raises an Exception? thequietcenter@gmail.com - 2014-09-09 06:55 -0700
Re: exit code of a script that raises an Exception? thequietcenter@gmail.com - 2014-09-09 07:41 -0700
Re: exit code of a script that raises an Exception? Ned Batchelder <ned@nedbatchelder.com> - 2014-09-09 11:22 -0400
| From | thequietcenter@gmail.com |
|---|---|
| Date | 2014-09-09 06:55 -0700 |
| Subject | exit code of a script that raises an Exception? |
| Message-ID | <efb77e4a-0510-49d3-8873-96714632a154@googlegroups.com> |
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
[toc] | [next] | [standalone]
| From | thequietcenter@gmail.com |
|---|---|
| Date | 2014-09-09 07:41 -0700 |
| Message-ID | <a757cb48-023c-4eb4-a1f6-0e07c9213bd5@googlegroups.com> |
| In reply to | #77728 |
On Tuesday, September 9, 2014 9:56:04 AM UTC-4, thequie...@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.
[toc] | [prev] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2014-09-09 11:22 -0400 |
| Message-ID | <mailman.13901.1410276152.18130.python-list@python.org> |
| In reply to | #77728 |
On 9/9/14 9:55 AM, thequietcenter@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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web