Yesterday I was told about an option in Visual Studio I had not previously been aware of, and boy, am I excited about it!
Break when an exception is: Common Language Runtime Exception: Thrown is un-checked by default.
Why do I care? How can this help me?
How many times have you seen code like this, where not only a good practice (like TryParse to avoid throwing an expensive exception) has not been implemented, but it’s also been wrapped in a try/catch without actually being handled.
Until yesterday’s new tip, I have found it close to impossible to reactively determine where code like this exists, since it doesn’t thrown an exception or break during debug when the exception is swallowed like that.
When you Check “Common Lanuguage Runtime: Thrown” prior to debugging, those swallowed CLR Exceptions will break when they’re thrown, no matter what the programmer’s “Handling” involved.
In this example, the code above could be replaced by something like this, which would prevent an exception from being thrown in the first place:
I am so excited about this I want to shout it from the rooftops…. right after I optimize a few inherited and/or legacy projects Woo hoo!
Thank you to Ryan Brown for showing me this!!!