Charles Mager
Guest
|
Hi
I'm developing a Word/Excel add-in, and what I've tried is only in Word at present.
I have a button that ultimately results in an exception being thrown on the Main Thread. I can see this in VS. I'm trying to work out how I catch these exceptions, as they appear to just be swallowed by the framework somewhere. So far I've tried subscribing to the following events:
Application.ThreadException
AppDomain.CurrentDomain.UnhandledException
ADXAddinModule.OnError
I've stuck breakpoints on all three handlers and nothing fires.
Am I missing something?
Thanks
Charlie |
|
Andrei Smolin
Add-in Express team
Posts: 19011
Joined: 2006-05-11
|
Hello Charlie,
You cannot handle exceptions globally in an Office add-in. This is because significant part of the code that your add-in invokes is unmanaged and if an exception occurs in it, there's no way to dispatch/translate the corresponding info so that a managed add-in could handle it.
As to the breakpoints, please check section "Breakpoints are not hit when debugging in Visual Studio" at http://www.add-in-express.com/docs/net-deploying-debugging-tips.php#breakpoints.
Andrei Smolin
Add-in Express Team Leader |
|
Charles Mager
Guest
|
Hi Andrei
Must have been having a long week - of course you're right, I remember this was the case in the VSTO add-ins I've written too for the same reason.
I think the solution I came up with then was to 'decorate' all button click handlers with something like:
public static void Execute(Action action)
{
try
{
action();
}
catch (Exception ex)
{
//show exception dialog
}
}
And I'll have to come up with something similar for unhandled exceptions in Word/Excel event handlers. If there's any better approach, please shout!
Re breakpoints - this wasn't quite the issue I was having, I was just explaining that the 'global exception handlers' I tried to add weren't being called. I haven't got any issue debugging in general.
Thanks
Charlie |
|
Andrei Smolin
Add-in Express team
Posts: 19011
Joined: 2006-05-11
|
Hello Charles,
This is a correct approach. Note that Add-in Express wraps raising every event that it provides in a try/catch block; if it encounters an exception, you get the OnError even on the add-in module. A similar approach is used with Add-in Express panes; see the ADXError event provided by the corresponding Manager component: ADXOlFormsManager, ADXExcelTaskPanesManager, etc.
Andrei Smolin
Add-in Express Team Leader |
|