Catch more than on exceptions : Except : Statement PYTHON TUTORIALS


PYTHON TUTORIALS » Statement » Except »

 

Catch more than on exceptions


import sys, traceback, math

try:
    n = float(raw_input("Please, enter a number: "))
    print "The sqrt of %f is %f" (n, math.sqrt(n))

except (ValueError, TypeError, OverflowError):
    print "This is the standard traceback message:"
    print ""
    traceback.print_exc()
    print "This is the customized traceback message:"
    print ""
    info = sys.exc_info()
    exc_type = info[0]
    exc_value = info[1]
    exc_traceback = info[2]

    trace = traceback.extract_tb(sys.exc_traceback)
    print "Exception Type:  ", exc_type
    print "Error Message:   ", exc_value
    print "File name:       ", trace[0][0]
    print "Error message:   ", trace[0][1]
    print "Line:            ", trace[0][2]
    print "Function:        ", trace[0][3]
else:
    print "Everything went just fine."



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Statement
» Except