开发者

Making a global exception handler for Visual Studio 2010 VsPackage

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开发者_JAVA技巧 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜