C#句柄中的try-catch块可以输入多个catch块吗?

Kev*_*ica -3 c# exception try-catch

我有一些像这样的代码:

try 
{
    doStuff();
}
catch(SpecificException) 
{
    if(e.Message == interestingMessage)
        doOtherStuff();
    else
        throw;
}
catch(Exception e)
{
    doSomethingElse();
}
Run Code Online (Sandbox Code Playgroud)

当第一个catch块重新抛出异常时,它会被第二个catch块捕获吗?

Cla*_*edi 5

不,如果您重新抛出异常,则将其执行到方法调用者.

if inside SpecificExceptioncatch表示您需要将该异常拆分为(至少)2种不同类型.