Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 586
IAdapter Avatar asked Feb 01 '11 12:02

IAdapter


1 Answers

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.

like image 128
Pieter van Ginkel Avatar answered Sep 27 '22 20:09

Pieter van Ginkel