How do I link thread exceptions from my c# code behind an Excel worksheet to an Exception handler I can't use the following code "Application.ThreadException += <<Global Thread Exception Method Path>>;", because of course the Application object in an Excel Template project is the Excel application therefore it does not have the ThreadException property. The problem is that I sometimes will have c# errors in my code behind, and nothing will pop up (I have to use messageboxes with try....catch blocks). I would like to link all handled c# exceptions to a Global method I have created. Any ideas



Re: Visual Studio Tools for Office Thread Exception

Misha Shneerson - MSFT

Unfortunately it is impossible to magically receive notifications about all exceptions.

Only exceptions coming from Windows Forms event handlers can be monitored using Application.ThreadException event. This is because WindowsForms are enclosing all their events into try/catch blocks.

Office events go directly through COM Interop which does not allow for this kind of exception notifications. If an exception is thrown inside COM event - the caller gets a failed HRESULT which in most cases is just ignored.

The only way to catch this events is by see setting up try/catch block of your own inside the event handler.