Visual Studio Developer Center > Visual Studio Forums > Visual Studio Tools for Office > [Word application-level add-in] Exception Handling
Ask a questionAsk a question
 

Answer[Word application-level add-in] Exception Handling

  • Monday, November 02, 2009 10:08 AMJason 8659876 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi

    I'm trying to handle all exceptions in my Word 2007 application-level add-in.

    I have a Windows Form, and if an exception is thrown when the OK button is clicked, I get "unhandled by user code" in VS 2008 SP1.

    This is despite having handlers set up for Application.ThreadException and AppDomain.CurrentDomain.UnhandledException

    I know I can catch and handle the exception within the form's code, but is there any way I can just have it handled by Application.ThreadException or AppDomain.CurrentDomain.UnhandledException? 

    thanks

    Jason


Answers

  • Tuesday, November 03, 2009 2:04 AMJason 8659876 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    OK, problem solved after a number of wasted hours.

    You need the [System.Diagnostics.DebuggerNonUserCodeAttribute()] annotation.

    Alternatively, unchecking the Visual Studio setting "Break when an exception is .. user-unhandled"  for CLR exceptions seemed to do the trick today.

    The MS documentation on exception handling in VSTO apps leaves a lot to be desired.  Even the 1000+ page Carter/Lippert tome says sweet fa about it!


All Replies

  • Tuesday, November 03, 2009 2:04 AMJason 8659876 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    OK, problem solved after a number of wasted hours.

    You need the [System.Diagnostics.DebuggerNonUserCodeAttribute()] annotation.

    Alternatively, unchecking the Visual Studio setting "Break when an exception is .. user-unhandled"  for CLR exceptions seemed to do the trick today.

    The MS documentation on exception handling in VSTO apps leaves a lot to be desired.  Even the 1000+ page Carter/Lippert tome says sweet fa about it!