Output exception arguments, string representation of exception,and the traceback : Exception Info « Exception « Python






Output exception arguments, string representation of exception,and the traceback

Output exception arguments, string representation of exception,and the traceback
import traceback

def function1():
   function2()

def function2():
   function3()

def function3():
   try:
      raise Exception, "An exception has occurred"
   except Exception:
      print "Caught exception in function3. Reraising....\n"
      raise

try:
   function1()
except Exception, exception:
   print "Exception caught in main program."
   print "\nException arguments:", exception.args
   print "\nException message:", exception
   print "\nTraceback:"
   traceback.print_exc()

           
       








Related examples in the same category

1.Get an exception's argumentGet an exception's argument
2.Print out exception infoPrint out exception info