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:

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)