I've just seen some of the worst code of my life... fortunately it was from an AutoGenerated application.
Lets start with this
pValue = Utility.GetParam("issue_id");Response_issue_id.Value = pValue;
if(Session["UserID"]!=null)
pValue = Session["UserID"].ToString();
else
pValue="";Response_user_id.Value = pValue;
pValue = Utility.GetParam("assigned_to");
Notice that after the else, you will see that there are two statements on one line. Due to the fact that there is no bracket, the 2nd statement will also be executed when the condition was met as well.
After that we see loads of
pValue = Utility.GetParam("assigned_to");
try
{
Response_assigned_to.SelectedIndex=Response_assigned_to.Items
.IndexOf(Response_assigned_to.Items.FindByValue(pValue));
}
catch{}
pValue = Utility.GetParam("priority_id");
try
{
Response_priority_id.SelectedIndex=Response_priority_id.Items
.IndexOf(Response_priority_id.Items.FindByValue(pValue));
}
catch{}
Where this pattern is repeated for about a dozen fields. Don't run this code with "Break when an exception is thrown" switched on.
However my personal favourite is
Decimal.Parse(CCUtility.GetFormattedNumeric(mydec,CCUtility.defaultReturnedNumeric.BlankString ));
The point here is that CCUtility.GetFormattedNumeric attempts to parse a string into a numeric (again with a try catch around a Decimal.Parse) and then returns ToString("0.#####"). If the string isn't a number then it returns the 2nd argument, which is CCUtility.defaultReturnedNumeric.BlankString but of course that fails the Decimal.Parse. Shame they didn't use the alternative value CCUtility.defaultReturnedNumeric.Zero and saved two exceptions being thrown.