How to: Handle Errors in Office Projects
Because of the way that managed code interacts with unmanaged code, Visual Studio does not display errors that are thrown by Microsoft Office applications. To see these errors, set the debugger to break on common language runtime exceptions.
Note
Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Working with Settings.
To break on common language runtime exceptions
On the Debug menu, click Exceptions.
Select the check boxes next to Common Language Runtime Exceptions.
All exceptions will now break into the debugger, including ones that you have handled and some first-chance exceptions from the runtime itself, which might not be relevant to your project. Errors referring to msosec not being found appear in every project, but are safe to ignore. These msosec exceptions will not affect your solution.
You can also use Try...Catch statements around your methods to catch exceptions. For more information, see How to: Test Code with a Try…Catch Block in Visual Basic and How to: Handle an Exception Using try/catch (C# Programming Guide).
By default, Visual Studio also does not display Just-In-Time debugging errors for Office projects; however, you can enable this feature so that you can see the errors that are raised. For more information, see Just-In-Time Debugging.
See Also
Concepts
Debugging in Document-Level Projects
Debugging in Application-Level Projects