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.

有帮助吗?

解决方案

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top