AppDomain的UnhandledException [英] AppDomain UnhandledException

查看:240
本文介绍了AppDomain的UnhandledException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个C#项目,并希望利用UnhandledException事件赶上我可以在我的项目已经错过了(希望不会有任何而是要在同一侧)任何异常。

I am working on a C# project and want to make use of the UnhandledException event to catch any exceptions I may have missed in my project (hoping there won't be any but to be on the same side).

我做了相当多的软件,所以我想打一个类库,我所有的项目都将使用,所以我想有一个函数,它把所有的我的所有项目的初始化的东西有没有我的代码复制并粘贴到每一个项目做同样的工作。

I make quite a bit of software so I want to make a class library that all of my projects will make use of so I want to have one function that does all of the initialisation stuff of all my projects without me having to copy and paste the code into each project to do the same work.

我想知道是,如果我在类库使用下面的代码未处理的异常事件。

What I am wondering is if I have in the class library the unhandled exception event using the following code

AppDomain currentDomain = AppDomain.CurrentDomain;
            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(currentDomain_UnhandledException);



请问未处理的异常只能从类库中使用,或将在此事件处理也可以从exeucted任何项目的引用类库。

Will the unhandled exception only be used from within the class library or will this event handle also be exeucted from any projects that the references the class library.

感谢您的帮助,您可以提供。

Thanks for any help you can provide.

推荐答案

假设所有项目在同一个AppDomain中运行,这将正常工作。我们有封装在众多应用程序之间共享一个共同的DLL这个确切的代码

Assuming that all of your projects are running in the same appdomain, this will work correctly. We have this exact code encapsulated in a common DLL that is shared among numerous applications.

另外一个建议:如果这是在Windows中使用窗体应用程序,你可能也想增加对 System.Windows.Forms.Application.ThreadException 。这可作为当例如,有人忘记异常处理添加到控制事件逆止

An additional suggestion: if this is used in Windows Forms applications, you probably also want to add a handler for System.Windows.Forms.Application.ThreadException. This serves as a backstop when, for example, someone forgets to add exception handling to a control event.

这篇关于AppDomain的UnhandledException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆