views:

30

answers:

1

I am trying to attach a unhandled exception handler for .NET excel addin. The problem is the exception handler is never called.

AppDomain.CurrentDomain.UnhandledException doesn't work - never fires the event.

Application.Current.DispatcherUnhandledException can't be used as Application is null in the excel addin code.

how do you wire an unhandled exception handler then?

+1  A: 

You might not be able to, since the application is actually an unmanaged application. You might have to just put try/catch blocks around flaky areas.

justin.m.chase
Correct. Since Excel is the caller, it is up to Excel to handle the Exception or not. If Excel handle's it, then there is no unhandled exception. If Excel does not handle it, then Excel crashes. It's that simple. Either way, the managed code execution ends at the COM Interop barrier. The key is not so much to surround all "flaky areas", but to use error handling around all entry points where Excel calls your code.
Mike Rosenblum