Generic catch for python
Exceptions are already printed by default before program termination. If you want to send the error somewhere else (not print it) you can do this:
try:
something()
except Exception as e:
send_somewhere(traceback.format_exception(*sys.exc_info()))
raise # reraises the exception
note that this format using the as
keyword is for python > 2.6. The old way was:
except Exception, e:
The traceback module is quite useful for formatting tracebacks. You can then write it to a logfile.