0
Python 3の次の例外がどのように初期化されるのか混乱します。基本例外はどのように初期化されていますか?
のPython 3ではclass MyException(Exception):
def __init__(self,msg,foo):
self.foo = foo
raise MyException('this is msg',123)
、この出力:
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がトレースバックに含まれていないため、私にとって意味があります。それがエラーのこの一般的なケースを処理するために特別にそこに置かれている__new__
方法を持っているという点で
Traceback (most recent call last):
File "exceptionTest.py", line 7, in <module>
raise MyException('this is msg',123)
__main__.MyException