I'm working with a native dll that somewhere throws a c0000005 exception (access violation) and ends up crashing my web service until the service is recycled. Is there a way to catch the exception?
I agree with the others... Fix the problem, but sometimes you inherit code and you just want to catch an unexpected violation in production.
In .net 4+ you can add the HandleProcessCorruptedStateExceptions attribute and it will come out as an Exception that you can catch. The call stack isn't horribly useful, but it's better than nothing.
C#
[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions]
public void SomeCSharpMethod()
try
{
// call managed code
}
catch (Exception ex)
{
Console.WriteLine("Exception");
}
C++
vector<int> myValues;
int a = myValues[1];
you can catch the exception using Microsoft SEH exception handler, but really you should fix whatever is wrong.
Cheers & hth.,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With