How to except the unexpected?
Paul Rubin
http
Sat Mar 4 00:10:22 EST 2006
Steven D'Aprano <steve at REMOVETHIScyber.com.au> writes:
> try:
> process_things()
> except ExpectedErrors:
> recover_from_error_gracefully()
> except ErrorsThatCantHappen:
> print "Congratulations! You have found a program bug!"
> print "For a $327.68 reward, please send the following " \
> "traceback to Professor Donald Knuth."
> raise
> except:
> print "An unexpected error occurred."
> print "This probably means the Internet is broken."
But this isn't good, it catches asynchronous exceptions like the user
hitting ctrl-C, which you might want to handle elsewhere. What you
want is a way to catch only actual exceptions raised from inside the
try block.
More information about the Python-list
mailing list