An interesting question came in last week around how to get around the “annoying” JIT-Attach Debugger dialog that pops up if an Application throws an unhandled exception, etc.
As all good programs should you can add a UnhandledExceptionHandler on the AppDomain object which should notify you of any unhandled exceptions and allow you to log them, etc. The Application will still terminate but at least you’ve been giving notification and have some way of figuring out what happened.
However this UnhandledException handler wasn’t working as expected, you still get the Debugger dialog pop up, if you hit continue on the dialog it turns out your handler does get called but this isn’t the right behavior, especially if your running on a server and wanting to get a process exit code, etc. Note – this still happens with Release Builds, not just debug!
After a bit of research it turns out that VS.NET and the .NET SDK adds a hook into the unhandled exception mechanism to get a jump on such exceptions and get a debugger in there. Quite neat, but frustrating!! J If you have a vanilla box with just the Framework this doesn’t happen.
You can change this by modifying the DbgJITDebugLaunchSetting DWORD value under HKLM\Software\Microsoft\.NETFramework to 1 it works as you’d expect; the other settings can be found here