Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle unhandled exception from a reference dll

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.

like image 356
Sumeshk Avatar asked Jan 06 '14 10:01

Sumeshk


1 Answers

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);
like image 198
Yanshof Avatar answered Oct 20 '22 05:10

Yanshof