Eric Wise

Life, Rants, and .NET

<July 2008>
SuMoTuWeThFrSa
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789


Navigation

Blogs I read

Just for fun

My Life

.NET Stuff

Subscriptions



Avoiding Try - Catch

Grant Killian has a good article about why a coder shouldn't use try-catch blocks in just any situation.  I am ashamed to admit that back when I first started using .NET I was guilty of the sin he speaks of.

What I wanted to add to his post was another very common poor usage of try-catch I have seen many inexperienced coders (including myself at one point in time) do.

   try

   {

      ddlMyDropDownList.Items.FindByValue(myValue).Selected = true;

   }

   catch(Exception ex)

   {

      //Do nothing or display some kind of warning message

   }

Bad Bad Bad!  Try this instead:

   ListItem li;

   li = myDropDownList.Items.FindByValue(myValue);

   if(li != null)

       li.Selected = true;

  

posted on Saturday, January 29, 2005 8:31 AM by ewise





Powered by Dot Net Junkies, by Telligent Systems