简体   繁体   中英

Handle unhandled exception from a reference dll

I have created ac# 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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM