I'm currently looking into reliability features and exception handling of C# / .NET
These are especially the HandleProcessCorruptedStateExceptions attribute and CER s with PrepareConstrainedRegions.
Now I was reading the reference source code of the SecureString class, as this is a place where it is highly security critical to keep data encrypted even in exceptional situations, and found places similar like this:
[HandleProcessCorruptedStateExceptions]
//...
RuntimeHelpers.PrepareConstrainedRegions();
try
{
Unprotect();
// ...
}
catch(Exception)
{
Protect();
throw;
}
finally
{
Protect();
// ...
}
What is the reason for the catch block? Isn't the finally block sufficient to re-protect data?
Or could those corrupted state exceptions only affect catch and terminate the application afterwards?