Making a global exception handler for Visual Studio 2010 VsPackage
Asked Answered
T

1

14

In previous versions of Visual Studio, there was a single entry point to an extension (more specifically, an addin), the OnConnect method. From there it was possible to perform all the Visual Studio operations, such as adding menu items, and setting up a global exception handler, to gracefully handle unhandled exceptions.

In Visual Studio 2010's VsPackage, things work differently - many parts of the application (such as IWpfTextView) are composed by MEF and loaded without the explicit control of the package, making handling any exceptions coming from those very difficult.

Without explicitly wrapping all such components in a try..catch of their own, how can I efficiently implement a global handler for (non-critical) exceptions in my VsPackage? Again, the goal is having something like ReSharper's exception dialog, where it can handle global exceptions without crashing the Visual Studio.

Tautonym answered 12/6, 2011 at 13:47 Comment(1)
Hm, man. I just wrote a letter to Elisha in which I am asking almost the same question. Duh.Generic
G
4

I have investigated this topic by reading official VsExtensibility forum and according to this and this threads there is no such one place to hook for catching all exceptions. So typical solution will be to use try... catches everywhere.

I suggest to use one of the AOP frameworks like PostSharp to accomplish this with attributes in order to eliminate tons of crappy duplicated code that's only purpose is to handle unhandled exceptions.

Generic answered 16/6, 2011 at 12:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.