我正在尝试捕获以下两个异常:
class TestException:
def __init__(self):
self.x = [1, 2, 3]
def main():
test_exception = TestException()
try:
test_exception.y[1] = 4.0
except (IndexError, AttributeError) as e:
raise e('Why does this not work?')
if __name__ == '__main__':
main()
但出现以下错误:
TypeError:“ AttributeError”对象不可调用
为什么会这样?因为以下方法可以正常工作:
raise AttributeError('This does work!')
感谢您的帮助。
答案 0 :(得分:0)
从@jonrsharpe开始,以下工作正常:
[SEVERE] built_value_generator:built_value on lib/client.dart (cached):
Unknown error in BuiltValueGenerator for myproject|lib/client.dart.
NoSuchMethodError: The method 'getParsedLibraryByElement' was called on null.
Receiver: null
Tried calling: getParsedLibraryByElement(Instance of 'LibraryElementImpl')
或
raise type(e)('This works now.')