What is the point of re-raising exceptions?

后端 未结 2 1095
不思量自难忘°
不思量自难忘° 2021-01-14 07:35

So I\'ve seen mention elsewhere of using the following to re-raise an exception.

try:
    whatever()
except:
    raise

What is the purpose

2条回答
  •  萌比男神i
    2021-01-14 07:56

    Your example code is pointless, but if you wanted to perform logging or cleanup that only occurs on failure, you could put that between the except: and the raise and you'd do that work and then proceed as if the original exception was bubbling normally.

提交回复
热议问题