Catch clearly defined exception from sub.submodule in python

Posted by mynthon on Stack Overflow See other posts from Stack Overflow or by mynthon
Published on 2010-05-17T09:54:30Z Indexed on 2010/05/17 10:00 UTC
Read the original article Hit count: 173

Filed under:
|

I have 3 files. xxx which imports xxx2 and xxx2 imports xxx3 which one raises OppsError exception.

xxx3.py:

class OppsError(Exception):pass

def go():
    raise OppsError()

xxx2.py:

import xxx3
xxx3.go()

xxx.py:

try:
    import xxx2
except xxx3.OppsError:
    print 'ops'

When i run xxx.py i get error NameError: name 'xxx3' is not defined. Is importing xxx3 inside xxx only way to catch OppsError?

© Stack Overflow or respective owner

Related posts about python

Related posts about exception