In Python, how do I inspect and then re-raise an exception while maintaining the original call stack?

后端 未结 1 456
傲寒
傲寒 2021-01-12 05:54

I\'ve got a situation where I\'m catching a specific exception type, inspecting the exception\'s message to check if it\'s actually an exception I want to catch, and then re

1条回答
  •  太阳男子
    2021-01-12 06:50

    Just do:

    raise
    

    instead of raise e. See the tutorial section on raising exceptions, and also the language reference on raise statements:

    If no expressions are present, raise re-raises the last exception that was active in the current scope. If no exception is active in the current scope, a TypeError exception is raised indicating that this is an error (if running under IDLE, a Queue.Empty exception is raised instead).

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