0

所以我想知道嵌套try-catch-finally块的行为。

我的意思是,如果在第一个finally块内,我们有另一个try-catch-finally块并且内部块发生异常怎么办finally

异常会被传播吗?它会在某个地方被抓住吗?

我应该在哪里捕获异常?在内部finally块中,或者如果它被传播,我应该从上面的代码中捕获它?

例子:

static bool Func()
{
    try
    {}
    catch
    {}
    finally
    {
        try
        {}
        catch
        {}
        finally
        {
           throw new ApplicationException();
        }
    }
}
4

1 回答 1

-1

Depends. You can handle the exception in your inner exception, but if you don't want to handle it, you can just THROW it so the outer Try Catch will 'receive' the exception.

See here for more detailed example :

于 2013-05-30T14:58:55.920 回答