我可以删除空的捕捉与抛? [英] Can I remove empty catch with throw?
问题描述
我希望这很简单。我工作在一个大的code-基地,综合素质好,但偶尔你得到一些这些:
I'm hoping this is straightforward. I work on a large code-base, the overall quality is good, but occasionally you get some of these:
try
{
// Calls a .NET remoting method.
}
catch
{
throw;
}
请注意,没有最后的逻辑和渔获不指定任何例外或做任何事情比我上面提供的其他。但是,我知道,捕捉和重新投掷可以改变调用堆栈中的异常详细信息。如果这种行为是因为一个.NET远程调用这里具体是什么我不知道的是。
Note there is no finally logic and the catch does not specify any exceptions or do anything other than what I've provided above. However, I know that catching and re-throwing can alter the call-stack in the exception details. What I'm not sure about is if this behaviour is here specifically because of a .NET remoting call.
它是安全的删除此的try-catch?到目前为止,我所看到的,是的,但我想我会仔细检查的第一个任何异常行为。
Is it safe to remove this try-catch? So far as I can see, it is, but I thought I'd double check for any odd behaviour first.
推荐答案
据我所知,赶上(例外前){抛出前}
重置堆栈跟踪。而就抓{抛出; }
不会。
As far as I know, catch (Exception ex) { throw ex }
resets the stack-trace. And just catch { throw; }
does not.
所以,如果你不上的错误进行任何额外的逻辑,如:日志记录,我不知道有什么理由不删除该catch。
So if you don't perform any additional logic on error, e.g. logging, I don't know any reason to not remove that catch.
这篇关于我可以删除空的捕捉与抛?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!