Click here to Skip to main content
15,885,898 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
we have one console application in which we have another class library that contains all the business functions in which we are using in main method of program file into that we are getting errors but that is not able to handle.

I find below code to add in program file to handle exception and create handler MyExceptionHandler.

AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyExceptionHandler);

In my project this only works when I have exception in Main method of program file, but when I have exception from Method of business function class it's not handling it.

Please suggest a better way to handle global exception.

What I have tried:

AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyExceptionHandler);
Posted
Comments
Graeme_Grant 14-Mar-17 9:21am    
Have you tried wrapping the call to the lib in a try...catch?
Poonam Patel 10678835 14-Mar-17 9:44am    
no, we don't want to deal with try catch.
Graeme_Grant 14-Mar-17 9:50am    
You need to catch the exception at some point using a try...catch otherwise the exception will bubble up to your UnhandledException. That is what the try...catch is for.
CHill60 14-Mar-17 10:52am    
A virtual 5 for this comment :-)
Graeme_Grant 14-Mar-17 11:02am    
:) "Resistance is futile" - The Borg...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900