Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I want to subscribe to the AppDomain.CurrentDomain.UnhandledException event to catch any errors as im trying a new design pattern where I dont want to put a try catch on every event.

usually in a win forms app there is a main entry point, but this is a class library that is called by another application.

Is there a main entry point in a class library where I can hook up this event, or is it just not possible in a class library unless im sure one method will get called before anything else?

like image 237
WraithNath Avatar asked Jun 09 '11 13:06

WraithNath


1 Answers

No, class libraries don't have a main entry point. If you feel like you need one, then you could conceptually create one virtually via your public API surface area. In other words, limit what objects are public and in those public objects make sure the call gets made at some point. That could be taken to the extreme of requiring a factory call of some kind to setup your library before doing anything.

like image 98
Paul Avatar answered Sep 30 '22 17:09

Paul