Catch occasional exceptions - curses

T

Thomas Lindgaard

Hello

I'm almost done with my webcrawler with a nice curses interface. But every
once in a while an exception is thrown and not caught, and because of the
use of curses I can't figure out which exceptions are thrown and from
where.

Is the a way to catch all exceptions not handled elsewhere and print them
to my log window? IE. something like:

if __name__ == 'main':
try:
# the whole program (more or less)
except CatchAllExceptionsInSomeMagicWay:
printExceptionToLog()
 
P

Peter Hansen

Thomas said:
Hello

I'm almost done with my webcrawler with a nice curses interface. But every
once in a while an exception is thrown and not caught, and because of the
use of curses I can't figure out which exceptions are thrown and from
where.

Is the a way to catch all exceptions not handled elsewhere and print them
to my log window? IE. something like:

if __name__ == 'main':
try:
# the whole program (more or less)
except CatchAllExceptionsInSomeMagicWay:
printExceptionToLog()

try:
#
except:
traceback.print_exc(sys.exc_info())

Variations on that using other functions in the traceback
module are easy...
 
T

Thomas Lindgaard

try:
#
except:
traceback.print_exc(sys.exc_info())

Variations on that using other functions in the traceback
module are easy...

OK - I've wrapped most of my main function and run the crawler... but it
hasn't thrown an exception yet, so I don't know if it does the job. But
thanks :)
 
J

Josh Close

I've found there is another easy way of doing this. Use sys.excepthook

def errorHandler():
# do error handingl
# this will catch all leftover excptions

sys.excepthook = errorHandler

this way you don't have to wrap the whole program in a tr/except

-Josh
 

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

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top