Someone on reddit asked for folks’ number one dotnet-related tip they wished they had known earlier and I wanted to write about one of the responses that resonated with me most.

If you haven’t already done this, I GUARANTEE it will help you find and fix 69% more bugs in your code.

Why 69%?

Because it’s a sex position. But also because we are only human, and exception-handling can be tricky. When I enabled this setting and ran my app I immediately found a handful of uncaught exceptions being thrown. The app still ran, but there’s a lot of wasted processing going on. It’s great to finally know where all those ThreadAbortedExceptions were coming from!

The hot tip is to enable all Common Language Runtime Exceptions in Visual Studio’s Exceptions Settings window.

Doing this will cause the debugger to break on any .NET exception, at the point of being thrown. Giving you all the information you need to squash them bugz.

How do you do it?

In Visual Studio (I use 2015), with your solution open, hit CTRL+Alt+E on your keyboard to bring up the Exceptions Settings window.

Then just put a checkmark in the Common Language Runtime Exceptions box.

DONE!

Wait…not done. After posting this, users on reddit informed me that this could get pretty annoying since .NET internally tends to throw a lot of exceptions. I didn’t notice this when testing because I left out one crucial setting!

In the debugger options (Tools -> Options -> Debugging) enable Just My Code so that it will only break on exceptions sourced from your application’s code. I had this enabled already and didn’t realize it should have been part of this post. Thanks to reddit user /u/CoderHawk for pointing this out.

There, NOW you’re done.

Try it and test your app, you might be surprised :)

I’ll have more posts like this so if you liked it, I’d love it if you could share the URL and consider signing up for my list to be notified when another post comes out.