How to catch all unhandled exceptions in a .net assembly (library type, not application)

I have an assembly containing several classes. This is an assembly like a class library, not an application for Windows forms. It is also single-threaded.

Is there a way to catch all the unhandled exceptions so that I can register them?

+3
source share
2 answers

In my opinion, such logic inside the library is not a good idea. I believe that the responsibility for deciding how to deal with exceptions (both processed and unprocessed) should be the responsibility for the application. However, you can see the AppDomain.UnhandledException . You can install such a handler for CurrentDomain and do something there. However, you limit the use of your library (for example, implying that the library will be used in only one domain). You will also receive notifications of all unhandled exceptions, even completely unrelated to your assembly.

, , , , (, UnhandledException, ).

+3
+2

Source: https://habr.com/ru/post/1741085/


All Articles