Showing errors explicitly in try... except

Peter Hansen peter at engcorp.com
Fri Apr 1 12:41:26 EST 2005


Harlin Seritt wrote:
> When using try... except... errors don't show up. Is there a way to
> force stderr despite using try...except? 

"force", no.  The "stderr" stuff is done by an "unhandled
exception" handler that is at the very top level, so
if you catch the exception, it will never see it to
print it.

Doing this will probably suffice, however:

import traceback
try:
     1/0

# one should avoid non-specific exception catching
# in most cases, but this is an example:
except:
     traceback.print_exc()


-Peter



More information about the Python-list mailing list