Catching Unhandled Exceptions
Hi,
I am trying to catch unhandled exceptions in my code for a c# workbook.
I have tried using the:
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(HandleException);
(this is set in the ThisWorkbook_Startup method)
but my HandleException method is never called and i get the default "Office document customistation is not available" error message.
This isn't ideal as the customisation breaks and stops working, I'd like to handle the exception myself and carry on.
The workaround is to put try catches on all my code but handling the unhandled exception would be better.
The exceptions only ever tend to be network timeouts, but occasionally something else goes wrong.
Thanks
Michael,
Does the unhandled exception happen when you are loading your customization? Or is the exception happening later on after you addin has loaded?
I really don't know the answer to this, but is it possible that the addin loader for the Office app also has subscribed to this event and doesn't pass it along to you (because they handle it by throwing up the Unhandled Exception UI)? If this is the case, you may be stuck putting try/catches everywhere. This isn't a bad thing though, as you will have more control over which events you want to catch at different places.
Cheers,
~Joe
Hi Michael
I think this will only work on Addin based solutions that are using the IDTExtensibility2 Interface in the OnConnection method as VSTO is possibly handling this you are not recieving the events that are being fired. Remember the VSTO solution has its own Managed stub that is creating an AppDomain and as such I presume you are trying to debug the issues in the solution/workbook.
Can you explain what you are trying to swallow.
Regards
i can probably get around my problems my using try catches, the problem occurs when saving the data in the spreadsheet back to the database - which occasionally times out - i should really be catching that anyway.
I'd just like to be able to handle any other unforeseen exceptions is a better manner than the default built in mechanism