【发布时间】:2016-10-17 16:35:39
【问题描述】:
我对 Python 3 中的以下异常如何初始化感到困惑。
class MyException( Exception ):
def __init__(self,msg,foo):
self.foo = foo
raise MyException('this is msg',123)
在 Python 3 中,此输出:
Traceback (most recent call last):
File "exceptionTest.py", line 7, in <module>
raise MyException('this is msg',123)
__main__.MyException: ('this is msg', 123)
如何初始化参数?我很惊讶引用显示了 args,因为我没有调用超类初始化程序。
在 Python 2 中,我得到以下输出,这对我来说更有意义,因为 args 不包含在回溯中。
Traceback (most recent call last):
File "exceptionTest.py", line 7, in <module>
raise MyException('this is msg',123)
__main__.MyException
【问题讨论】:
标签: python python-3.x exception python-2.x