How to create a global error handler in a Windows Form application?

I think there is a component that allowed the creation of global error handling.

For example, I myself make an exception when something bad happens, for example

throw new ArgumentNullException("playlist is empty"); 

How can I catch him globally?

+6
c # error-handling components global
source share
3 answers

You can execute this through AppDomain.UnhandledException or Application.ThreadException .

For more information on what these events do and what the difference is in these events, see the documentation. The idea is that AppDomain.UnhandledException always works. Application.ThreadException is specifically for unhandled user interface exceptions.

+8
source share

Exception Handling Globally ...

Windows application

System.Windows.Forms.Application.ThreadException event

Commonly used in the main method. See MSDN Thread Exception

Asp.Net

System.Web.HttpApplication.Error event

Commonly used in the Global.asax file. Refer Global MSDN Handlers Global.asax

Console application

System.AppDomain.UnhandledException event

Commonly used in the main method. See MSDN UnhandledException

+2
source share

All Articles