# This file shows an example of getting the exception info if you # decide to catch 'except:' In general, you shouldn't do that, # catch the more specific types when you can. # # Much of this info is from: http://docs.python.org/lib/module-sys.html # # Dan Fleck # Spring 2008 import sys def test(): valid = False # Is the number valid while not valid: try: myNum = input('Give me a number :') x = 10 / myNum valid = True except: # Catch any exception, but if you STILL want the info about it, you need # to get the informationn about the exception that caused the problem exceptionInfo = sys.exc_info() # Ask for the info theExceptionType = exceptionInfo[0] theExceptionObject = exceptionInfo[1] #theTraceback = exceptionInfo[2] # Bad to do... see http://docs.python.org/lib/module-sys.html print 'A %s exception was caused because: %s ' %(theExceptionType, theExceptionObject) print '10 divided by your number is:', x valid = True test()