A temporary exception class is defined dynamically using 'type' in a python script meant to be used as module. When an instance of this class is caught in importing script it doesn't recognize the class. Below is code snippet
# the throwing module, defines dynamically
def bad_function():
ExceptionClass = type( "FooBar", (Exception,),
{ "__init__": lambda self, msg: Exception.__init__(self, msg) })
raise ExceptionClass("ExceptionClass")
the using code
import libt0
try:
libt0.bad_function()
#except libt0.FooBar as e:
#print e
except Exception as e:
print e
print e.__class__
can it be explained why libt0.FooBase is not visible to this script? observer output of last line.