How do I get the stack trace from an Exception Object in Python?

前端 未结 1 440
轻奢々
轻奢々 2021-01-19 05:15

How can I get the full stack trace from the Exception object itself?

Consider the following code as reduced example of the problem:

last_exception =          


        
相关标签:
1条回答
  • 2021-01-19 05:56

    Edit: I lied, sorry. e.__traceback__ is what you want.

    try:
        raise ValueError
    except ValueError as e:
        print( e.__traceback__ )
    
    >c:/python31/pythonw -u "test.py"
    <traceback object at 0x00C964B8>
    >Exit code: 0
    

    This is only valid in Python 3; you can't do it in earlier versions.

    0 讨论(0)
提交回复
热议问题