捕捉异常的任何值,并立即重新提升? [英] Any value in catching an exception and immediately raising it again?

查看:116
本文介绍了捕捉异常的任何值,并立即重新提升?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

只有加注有异常吗?

有没有什么价值重新提出异常,没有其他代码之间?

Is there any value to re-raising an exception with no other code in between?

try:
  #code
except Exception:
  raise

我最近正在看一些代码,看到几个这样的块,除了块外没有额外的,但另一个加注。我假设这是一个错误的决策,我是对的吗?

I was recently looking through some code and saw a few blocks like these with nothing extra in the except block but another raise. I assume this was a mistake and poor decision making, am I right?

推荐答案

之前我已经看过类似的代码一套)可怕的VB.NET项目。或者意图是捕获和记录例外,而没有回来完成日志记录,或者他们听到你必须捕获例外,实现了这个功能,而别人决定应该重新加注。

I've seen similar code before in a (set of) horrible VB.NET projects. Either the intent was to catch and log exceptions, without ever coming back to finish the logging, or they heard "you must catch exceptions", implemented this functionality, and someone else decided it should just re-raise.

上述代码没有任何好处。

There is no benefit to the above code.

这篇关于捕捉异常的任何值,并立即重新提升?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆