When running application in Visual Studio there is a setting which allow debugger to break anytime some specified exception is being thrown (even if it's properly caught by the application).
This is a very useful feature because in my application some exceptions (e.g. null reference) should never occur and the programmer should write a code in a way to avoid them (e.g. always perform null-check where null could appear). Thanks to the above mentioned feature my debugger will always break directly at the place of bug when this unwanted exception occur.
Now I would like to inject the similar logic to the release code. I would like every instance of some exception be logged with a stacktrace whenever it occurs even if this exception is caught and handled in the code. Is there such a mechanism in C#?
I could obviously add (catch NullReferenceException)
clause to all try/catch
blocks, but this would be very tedious.