是否有理由两次抛出异常?

Joh*_*ohn 2 c# exception-handling try-catch throw

调试生产代码我遇到了一些我以前从未见过的东西,并且我没有意识到有效的目的.在我们的一个控制器的几种方法中,我们有try-catch块.有趣的是,其中一个捕获中有2个抛出语句.

有没有理由有2个抛出语句?如果是这样,在什么情况下这是有道理的?

        try
        {
           //statements
        }
        catch (SoapException se)
        {
            //Log statement
            return null;
        }
        catch (Exception ex)
        {
            //Log statement
            throw;
            throw;
        }
Run Code Online (Sandbox Code Playgroud)

Nic*_*man 10

没有理由throw两次.throw永远不会达到第二个.

它也类似于

public int GetNumber()
{
    return 1;
    return 2; // Never reached
}
Run Code Online (Sandbox Code Playgroud)

更新

Resharper是一个很好的工具来检查这样的事情.

在这种情况下,它将灰显第二个throw并告诉你它无法访问.

在此输入图像描述