Handle unhandled exception from a reference dll

4.5k views Asked by At

I have created a c# dll to handle all the unhandled exceptions from the application.

added

AppDomain appDomain = AppDomain.CurrentDomain;
appDomain.UnhandledException += new UnhandledExceptionEventHandler(MyErrorHandler);

code in my dll project , added reference to my application.

while debugging if my application throws an unhanlded exception it is automatically caught from the dll and i successfully logged to a file.

But when my application is deployed ( or execute my application directly ( double click the exe)) the dll is not able to catch the unhandled exception from the application.

1

There are 1 answers

1
Yanshof On BEST ANSWER

See this on MSDN

You can try to use the add handler to threadException of the application and also the CurrentDomain Unhandled Exception like you write in your code

Application.ThreadException += new ThreadExceptionEventHandler(Error_.MyExc);
Application.SetUnhandledExceptionMode(Error_.MyCatchExc);

// from your code 
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyErrorHandler);