我有以下代码示例,
class Outer:
class InnerException(Exception): pass
def raise_inner(self):
raise Outer.InnerException()
def call_raise(self):
try:
self.raise_inner()
except Outer.InnerException as e:
print "Handle me"
Outer().call_raise()
我想做的不是Outer.InnerException
只在 Outer 类中使用 use InnerException
,简而言之就是这样
class Outer:
class InnerException(Exception): pass
#InnerException = Outer.InnerException .. something like this, create some alias
def raise_inner(self):
raise InnerException()
def call_raise(self):
try:
self.raise_inner()
except InnerException as e:
print "Handle me"
Outer().call_raise()