Can I add a handler to AppDomain.CurrentDomain.UnhandledException in the class library

I want to subscribe to the AppDomain.CurrentDomain.UnhandledException event to catch any errors as I try to create a new design template where I don't want to put a catch attempt in every event.

Typically, a winnings application has a primary entry point, but it is a class library called by another application.

Is there a main entry point in the class library where I can connect this event, or is it just not possible in the class library, if I am sure that any method will be called first?

+5
source share
2 answers

, . , , API. , , , , - . factory , - .

+1
// Set the unhandled exception mode to force errors to go through our handler. 
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

// Add the event handler for handling thread exceptions to the event.
AppDomain.CurrentDomain.UnhandledException += 
    new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

, - , ala assingning app.config, .

, . , , , , ...

, , , .

EDIT , , - IoC, . , , - .

.

0

All Articles