[Tutor] Logging exceptions, but getting stderr output instead
Terry Carroll
carroll at tjc.com
Wed May 25 20:35:25 EDT 2016
On Wed, 25 May 2016, Alex Hall wrote:
> You're not missing anything; I wasn't clear. I wasn't sure if raise or
> sys.exit(1) were the preferred ways, or if there was some other way I
> didn't know about.
If you're aborting because of the exception after unsuccessfully trying to
handle it, you can always just use "raise" with no operands, which will
re-raise the underlying exception. That's what I usually do:
try:
1/0
except ZeroDivisionError:
print "oops."
raise
prints:
oops.
Traceback (most recent call last):
File "[...]\test.py", line 2,
in <module>
1/0
ZeroDivisionError: integer division or modulo by zero
More information about the Tutor
mailing list