views:

9

answers:

1

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?

+1  A: 

As far as I know, it is (unless you are willing to replace OppsError with a built-in exception that is already known to xxx or to catch a more general exception instead of OppsError from which OppsError is derived).

Tamás