instance __class__ is the exception class as we've seenusing exception for the general exception name here would catch all nonexit exceptionssimilar to an empty except but less extremeand still giving access to the exception instance and its class even sousing the instance object' interfaces and polymorphism is often better approach than testing exception types--exception methods can be defined per class and run genericallytryexcept general as instanceinstance method(does the right thing for this instance as usualbeing too specific in python can limit your code' flexibility polymorphic approach like the last example here generally supports future evolution better than explicitly type-specific tests or actions displaying errors and tracebacks finallythe exception traceback object available in the prior section' sys exc_info result is also used by the standard library' traceback module to generate the standard error message and stack display manually this file has handful of interfaces that support wide customizationwhich we don' have space to cover usefully herebut the basics are simple consider the following aptly named filebadly pyimport traceback def inverse( )return tryinverse( except exceptiontraceback print_exc(file=open('badly exc'' ')print('bye'this code uses the print_exc convenience function in the traceback modulewhich uses sys exc_info data by defaultwhen runthe script prints the error message to file--handy in testing programs that need to catch errors but still record them in fullc:\codepython badly py bye :\codetype badly exc traceback (most recent call last)file "badly py"line in inverse( file "badly py"line in inverse return zerodivisionerrordivision by zero exception idioms