Skip to content

Instantly share code, notes, and snippets.

@rantav
Created January 2, 2013 13:55
Show Gist options
  • Save rantav/4434741 to your computer and use it in GitHub Desktop.
Save rantav/4434741 to your computer and use it in GitHub Desktop.
import sys
import traceback
try:
5 / 0
except ZeroDivisionError, e:
print e
# this will just print "integer division or modulo by zero"
# but if you try this:
exception_type, exception_value, exception_traceback = sys.exc_info()
print "Traceback: %s" % traceback.format_tb(exception_traceback)
print "value: %s" % exception_value
print "type: %s" % exception_type
# This will print:
#
# Traceback: [' File "tmp.py", line 4, in <module>\n 5 / 0\n']
# value: integer division or modulo by zero
# type: <type 'exceptions.ZeroDivisionError'>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment