I would like to have some kind of catch-all exceptions mechanism in the root of my code, so when an app terminates unexpectedly I can still provide some useful logging.
Something along the lines of
static void Main () {
if (Debugger.IsAttached)
RunApp();
else {
try {
RunApp();
}
catch (Exception e) {
LogException(e);
throw;
}
}
}
While this all works fine, my problem is when I want to attach the debugger after the exception has been raised.
Since the exception escapes to the runtime, windows will prompt to attach visual studio, except, since it has been rethrown, all locals and parameters further up the stack have been lost.
Is there anyway to log these exceptions, while still providing a way to attach the debugger and retain all useful information?