IAdapter
IAdapter

Reputation: 64707

How to create global error handler in Windows Form Application?

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?

Upvotes: 6

Views: 13679

Answers (3)

Ajay
Ajay

Reputation: 2080

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

Upvotes: 2

Pieter van Ginkel
Pieter van Ginkel

Reputation: 29632

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.

Upvotes: 9

Related Questions