Getting the exception value in Python

后端 未结 7 947
一个人的身影
一个人的身影 2021-01-29 20:15

If I have that code:

try:
    some_method()
except Exception, e:

How can I get this Exception value (string representation I mean)?

7条回答
  •  后悔当初
    2021-01-29 20:33

    To inspect the error message and do something with it (with Python 3)...

    try:
        some_method()
    except Exception as e:
        if {value} in e.args:
            {do something}
    

提交回复
热议问题