3

現在、 C# / .NETの信頼性機能と例外処理について調べています。

これらは、特にHandleProcessCorruptedStateExceptions属性とCERですPrepareConstrainedRegions

SecureStringこれは、例外的な状況でもデータを暗号化することが非常に重要な場所であるため、クラスの参照ソース コードを読んでいたところ、次のような場所が見つかりました。

[HandleProcessCorruptedStateExceptions]
//...

    RuntimeHelpers.PrepareConstrainedRegions();
    try
    {
        Unprotect();
        // ...
    }
    catch(Exception)
    {
        Protect();
        throw;
    }
    finally
    {
        Protect();
        // ...
    }

catchブロックの理由は何ですか?finallyブロックはデータを再保護するのに十分ではありませんか?

それとも、これらの破損状態の例外はcatch、後でアプリケーションに影響を与えて終了するだけでしょうか?

4

2 に答える 2

0

Finally blocks are almost always called, except in a few cases. See

Does the C# "finally" block ALWAYS execute? for more.

So yes, the protect is always called in the Finally.

于 2012-01-23T17:22:12.447 に答える