MSVS C# fastest way to remove try-catch blocks?

You can change the option here:

Debug -> Exceptions -> CLR Exceptions -> Check the "Thrown" checkbox.

This causes the compiler to break whenever an exception is thrown, before checking any catch blocks.


This is a horrible programming practice. I once saw this as a bug mess up someone's database.

It is my firm opinion you are better off letting your program die a fiery death than mindlessly continue on in an unknown state.

I would do a find and replace on MessageBox.Show(ex with throw //MessageBox.Show(ex and replace them all. You will have to manually find the ones that should really be there and put them back.


Visual Studio's Regex search is pretty powerful, however it is a bit tricky to use, here is something that you might find useful in searching for your above code: (Note in the find dialog box, in the Options section choose "Use: Regular Expressions")

Will find your bad catches:

catch.*\n+:b+{[.:b\n]MessageBox.[.:b\n]*}

If you want to do a straight replace with a throw:

catch\n{\nthrow;\n}

Tags:

Try Catch