How to create global error handler in Windows Form Application?

你。 提交于 2019-12-04 12:18:13

问题


I think there was a component that allowed to create global error handling.

For example I myself throw exception when something bad happens, for example

throw new ArgumentNullException("playlist is empty");

How can I catch it globally?


回答1:


MSDN is your friend: http://msdn.microsoft.com/en-us/library/system.windows.forms.application.threadexception.aspx




回答2:


You can accomplish this either through AppDomain.UnhandledException or Application.ThreadException.

See the documentation for more details on what these events do and what the difference is for these events. The idea is that AppDomain.UnhandledException always works. Application.ThreadException is specifically for unhandled UI exceptions.




回答3:


To Handle Exceptions Globally...

Windows Application

System.Windows.Forms.Application.ThreadException event

Generally Used in Main Method. Refer MSDN Thread Exception

Asp.Net

System.Web.HttpApplication.Error event

Normally Used in Global.asax file. Refer MSDN Global.asax Global Handlers

Console Application

System.AppDomain.UnhandledException event

Generally used in Main Method. Refer MSDN UnhandledException



来源:https://stackoverflow.com/questions/4862841/how-to-create-global-error-handler-in-windows-form-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!