Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

try-catch

I took over an incomplete project and to my utter disbelieve, every single function is wrapped with try-catch statements in this same format:

try
{
   // work work.
}
catch(Exception ex)
{
   MessageBox.Show(ex.Message, ...);
}

As I search SO for a method to quickly remove all these try-catch blocks, I find that people are actually looking for method to automatically wrap their functions with try-catch! hmmm... Is that good programming practice at all? Is there is method to remove all blocks instead so that it makes debugging easier and allows me to really solve the exceptions?

like image 719
Jake Avatar asked Mar 21 '11 12:03

Jake


2 Answers

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.

like image 66
FreeAsInBeer Avatar answered Oct 23 '22 03:10

FreeAsInBeer


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.

like image 38
dwidel Avatar answered Oct 23 '22 05:10

dwidel