Showing errors explicitly in try... except

H

Harlin Seritt

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

thanks,

Harlin Seritt
 
J

John Roth

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

If you're looking for stack traces, look at the inspect and
traceback modules. They contain the tools to do just
about anything you need for error reporting. Also there
is a logger module somewhere so you can put the stuff
somewhere permanent if you want.

John Roth
 
P

Peter Hansen

Harlin said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top