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
Sat, Jan 29 2005 8:31 AM
by
Eric Wise