Exception problem with module

Joseph L. Casale jcasale at activenetwerx.com
Tue May 13 12:59:46 EDT 2014


I am working with a module that I am seeing some odd behavior.

A module.foo builds a custom exception, module.foo.MyError, its done right
afaict.

Another module, module.bar imports this and calls bar.__setattr__('a_new_name', MyError).

Now, not in all but in some cases when I catch a_new_name, my code raises a new
exception:

During handling of the above exception, another exception occurred:

  File "C:/dir/test.py", line 12, in <module>
    except a_new_name as exc:
TypeError: catching classes that do not inherit from BaseException is not allowed

So, I wont suggest the assignment in bar added anything, nor would I do this, but
its what I am working with. Why might this happen? MyError subclasses Exception
and calls super passing back args.

This has something to do with the assignment in bar, catching MyError obviously works.

Any ideas?
jlc


More information about the Python-list mailing list