문제

I've got a weird symptom in an application, where try/catches inside the handler for UnhandledExceptions don't work: (that is a breakpoint inside the catch does not get hit, even if the breakpoint inside the try does).

Obviously searching for 'exception unhandled inside UnhandledException' is not working very well for me.

I've tried doing a mini proof-of-concept, and unfortunately that one works.

So while I'm trying to track down the root of the problem, if anyone here has any ideas where to look I'd be greatful.

(We recently changed from XP to Windows7, and .Net 4.5 from 4.0 - I'm pretty certain that previously this worked).

EDIT: Looks like it's provoked by a call down to a (managed) C++ library which is throwing a System.AccessViolationException. Strangely, if I replace the call with a throw new AccessViolationException, it does do what I want...

도움이 되었습니까?

해결책

You wrote, "We recently changed ... .Net 4.5 from 4.0 - I'm pretty certain that previously this worked." but the following seems worth adding, because pretty sure really means not certain :-)

I read somewhere that AccessViolationException cannot occur in managed code, but may be trapped by the runtime for unmanaged code. Maybe the C++ library calls into unmanaged code?

In .NET 4+ the process will terminate after AccessViolationException. Your exception handler will be ignored. This is among a group of exception types considered unrecoverable: Corrupted State Exceptions. In .NET 4+ you will need to customise the app config to override this behaviour.

다른 팁

Be sure that you try to catch System.AccessViolationException and not native Access Violation error.

When you do throw new AccessViolationException it throws System.AccAccessViolationException. If library that you calls is native it can throw native Access Violation error, but .NET catch block normally can catch only managed exceptions.

try this: i think we can't handle Unhandeled exception and have to exit application in finally. http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top