Catch clearly defined exception from sub.submodule in python -


I have 3 files xxx which imports xxx2 and xxx2 imports xxx3, which raises an upsus error exception.

xxx3.py:

  Class OppsError (exception): pass def go (): OppsError () Increase  

xxx2.py:

  import xxx3 xxx3.go ()  

xxx.py :

  Try: Import xxx2 except xxx3. Ops error: print 'ops'  

when I run xxx.py Error gets nameError: name 'xxx3' is not defined . What xxx3 to xxx only OppsError

"post-text" itemprop = "text">

is the only catch The way to import, I know, this (unless you want to replace OppsError with an implicit exception, which is already known to xxx or instead To get more general exception, OppsError gets OppsError ).


Comments