Well, in .NET 4 Microsoft added the HandleProcessCorruptedStateExceptions attribute:
HandleProcessCorruptedStateExceptionsAttribute Class
I want to test this
Test HandleProcessCorruptedStateExceptions feature:
using System.Diagnostics;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
...
[HandleProcessCorruptedStateExceptions]
public void HandleCorruptedStateException()
{
try
{
var ptr = new IntPtr(42);
Marshal.StructureToPtr(42, ptr, true);
}
catch(Exception ex)
{
Debug.WriteLine(ex.Message);
}
}