2

Is it possible to catch Exceptions that are handled by an external (legacy) Assembly?

I don't think I can catch those exceptions since they are already handled, but similarly to Visual Studio "break on all exceptions" I thought that maybe I could at least get some notification about the exception.

e.g.: MyProduct.exe calls Utils.dll and Utils.dll is swallowing all exceptions, and doesn't return any information if something wrong happened.

PS: Modifying that external assembly is obviously an alternative, but it's very hard because it's actually spread across hundreds of customized copies

drizin
  • 1,737
  • 1
  • 18
  • 44

1 Answers1

4

You can subscribe to the AppDomain.FirstChanceException event to get notified of exceptions:

This event is only a notification. Handling this event does not handle the exception or affect subsequent exception handling in any way. After the event has been raised and event handlers have been invoked, the common language runtime (CLR) begins to search for a handler for the exception. FirstChanceException provides the application domain with a first chance to examine any managed exception.

stuartd
  • 70,509
  • 14
  • 132
  • 163
  • Thanks, @stuartd. This is exactly what I was looking for. In case someone wants a brief summary [this answer](http://stackoverflow.com/a/564697/3606250) is also helpful. – drizin Feb 15 '17 at 20:16