Consider the following two modules: prog.py and err.py. both of which are examples of a much larger program that exhibits this problem. I need to split the functionality into smaller source files, each with a test bench.
Err.py includes a test bench. When it creates a prog object, depending on how the exception is raised, the exception hits or not.
It seems that although prog.py imports err objects in the "from err import" expression, the module name is still displayed (erroneous?), But it seems to erroneously refer not to the module itself
Is this a bug in Python 2.7 or is this the intended behavior?
just get both files and run err.py to figure out what i mean ..
First file:
from err import *
class prog(object):
def func1(self):
raise MySubError
def func2(self):
doError()
:
import prog
import inspect
import sys
class myError(Exception):
pass
class MySubError(myError):
pass
def doError():
raise MySubError
if __name__=="__main__":
p=prog.prog()
try:
doError()
except MySubError as er:
print type(er)
print "Captured 1"
except Exception as er:
print type(er)
print "Not Captured 1"
try:
p.func1()
except MySubError as er:
print type(er)
print "Captured 2"
except Exception as er:
print type(er)
print "Not captured 2"
try:
p.func2()
except MySubError as er:
print type(er)
print "Captured 3"
except Exception as er:
print type(er)
print "Not captured 3"
, - err , , err.MySubError, MySubError. , .....
:
<class '__main__.MySubError'>
Captured 1
<class 'test.MySubError'>
Not captured 2
<class 'test.MySubError'>
Not captured 3