Sys.excepthook -vs- Handled Exceptions
I noticed that exceptions that are handled do not result in a call to sys.excepthook... which makes sense in retrospect. But, how do I log or otherwise customize the way that handl
Solution 1:
You can get the Exception
and print info about it or log that with a logging call of your own:
try:
1/0except Exception, e:
print("a {0} was not raised".format(e.__class__.__name__))
# or logging.yourLogger(e.__class__.__name__)pass
Result:
a ZeroDivisionError was not raised
If you were looking for some kind of Global Exception Handling, that is probably not trivial or not possible without enclosing everything in try/except
.
Post a Comment for "Sys.excepthook -vs- Handled Exceptions"