I have an assembly containing a number of classes. This is a class library type assembly, not a windows forms application. It’s also single threaded.
Is there a way to catch all un-handled exceptions so that I can log them?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In my opinion, putting such logic inside library is not a good idea. I think it should be application responsibility to decide how to deal with exceptions (both handled and unhandled). However you might look at AppDomain.UnhandledException. You can install such handler for CurrentDomain and do something there. However doing this way you are restricting usages of you library (for example implying that library would be used only in one domain). Also you will receive notifications for all unhandled exceptions even totally unrelated to your assembly.
I think that better idea is to allow developers that use your library to do their job dealing with all unhandled exceptions (possibly with UnhandledException installed by the application).