Is there anything I can do to catch an AccessViolationException? It is being thrown by a unmanaged DLL that I don\'t control.
you can wrap the call to the unmanaged DLL with a try-catch block. AccessViolationExceptions can be caught normally. Executing the following code shows both messages:
try
{
throw new AccessViolationException();
}
catch (Exception e)
{
MessageBox.Show(e.Message + e.StackTrace, e.Message, MessageBoxButtons.OK, MessageBoxIcons.Error);
}
MessageBox.Show("Still running..");
Edit: .NET 4 introduced a change in behavior, it is no longer possible to catch corrupted state exceptions unless you specifically "ask" the runtime to do so.