Exception handling!
-
Just got back from vacation and lots of people are gone. Have to fix a "finished" project which of course doesn't work on-site. Customer got very angry that many things just doesn't work.
Here is one of all the nice things I found!
<FONT size=2></FONT><FONT color=#0000ff size=2>public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>static</FONT><FONT size=2> </FONT><FONT color=#2b91af size=2>IntranetUserCollection</FONT><FONT size=2> GetUsersFromLDAPSearch(Ldap.</FONT><FONT color=#2b91af size=2>LdapSearch</FONT><FONT size=2> searcher)
{
</FONT><FONT color=#2b91af size=2>IntranetUserCollection</FONT><FONT size=2> coll = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#2b91af size=2>IntranetUserCollection</FONT><FONT size=2>();
</FONT><FONT color=#0000ff size=2>while</FONT><FONT size=2>(searcher.Read())
{
</FONT><FONT color=#2b91af size=2>IntranetUser</FONT><FONT size=2> retUser = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#2b91af size=2>IntranetUser</FONT><FONT size=2>();
</FONT><FONT color=#0000ff size=2>try
</FONT><FONT size=2>{
retUser.DomainUserName = EPiServer.</FONT><FONT color=#2b91af size=2>Global</FONT><FONT size=2>.EPConfig[</FONT><FONT color=#a31515 size=2>"EPsLdapDomain"</FONT><FONT size=2>] + </FONT><FONT color=#a31515 size=2>"\\"</FONT><FONT size=2> + searcher[</FONT><FONT color=#a31515 size=2>"sAMAccountName"</FONT><FONT size=2>][0];
}
</FONT><FONT color=#0000ff size=2>catch
</FONT><FONT size=2>{
</FONT><FONT color=#0000ff size=2>continue</FONT><FONT size=2>;
}
</FONT><FONT color=#0000ff size=2>try
</FONT><FONT size=2>{
retUser.FirstName = searcher[</FONT><FONT color=#a31515 size=2>"givenName"</FONT><FONT size=2>][0];
}
</FONT><FONT color=#0000ff size=2>catch</FONT><FONT size=2>{}
</FONT><FONT color=#0000ff size=2>try
</FONT><FONT size=2>{
retUser.LastName = searcher[</FONT><FONT color=#a31515 size=2>"sn"</FONT><FONT size=2>][0];
}
</FONT><FONT color=#0000ff size=2>catch</FONT><FONT size=2>{}
</FONT><FONT color=#0000ff size=2>try
</FONT><FONT size=2>{
retUser.Email = searcher[</FONT><FONT color=#a31515 size=2>"mail"</FONT><FONT size=2>][0];
}
</FONT><FONT color=#0000ff size=2>catch</FONT><FONT size=2>{}
</FONT><FONT color=#0000ff size=2>try
</FONT><FONT size=2>{
retUser.Telephone1 = searcher[</FONT><FONT color=#a31515 size=2>"telephoneNumber"</FONT><FONT size=2>][0];
}
</FONT><FONT color=#0000ff size=2>catch</FONT><FONT size=2>{}
</FONT><FONT color=#0000ff size=2>try
</FONT><FONT size=2>{
retUser.Telephone2 = searcher[</FONT><FONT color=#a31515 size=2>"mobile"</FONT><FONT size=2>][0];
}
</FONT><FONT color=#0000ff size=2>catch</FONT><FONT size=2>{}
</FONT><FONT color=#0000ff size=2>try
</FONT><FONT size=2>{
retUser.Title = searcher[</FONT><FONT color=#a31515 size=2>"title"</FONT><FONT size=2>][0];
}
</FONT><FONT color=#0000ff size=2>catch</FONT><FONT size=2>{}
</FONT><FONT color=#0000ff size=2>try
</FONT><FONT size=2>{
</FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> areaID = </FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2>.MinValue;
</FONT><FONT color=#0000ff size=2>string</FONT><FONT size=2> rssUrl = </FONT><FONT color=#0000ff size=2>string</FONT><FONT size=2>.Empty;
</FONT><FONT color=#0000ff size=2>string</FONT><FONT size=2> areaName = searcher[</FONT><FONT color=#a31515 size=2>"company"</FONT><FONT size=2>].Length > 0 ? searcher[</FONT><FONT color=#a31515 size=2>"company"</FONT><FONT size=2>][0]:</FONT><FONT color=#a31515 size=2>""</FONT><FONT size=2>;
GetBusinessAreaID(areaName, </FONT><FONT color=#0000ff size=2>out</FONT><FONT size=2> areaID, </FONT><FONT color=#0000ff size=2>out</FONT><FONT size=2> rssUrl);
retUser.DefaultBusinessAreaCategoryID = areaID;
</FONT><FONT color=#2b91af size=2>Util</FONT><FONT size=2>.RssFeedURL = rssUrl;
}
</FONT><FONT color=#0000ff size=2>catch</FONT><FONT size=2>{}
</FONT><FONT color=#0000ff size=2>try
</FONT><FONT size=2>{
retUser.Office = searcher[</FONT><FONT color=#a31515 size=2>"physicalDeliveryOfficeName"</FONT><FONT size=2>][0];
}
</FONT><FONT color=#0000ff size=2>catch</FONT><FONT size=2>{}
</FONT><FONT color=#0000ff size=2>try
</FONT><FONT size=2>{
retUser.Department = searcher[</FONT><FONT color=#a31515 size=2>"department"</FONT><FONT size=2>][0];
}
</FONT><FONT color=#0000ff size=2>catch</FONT><FONT size=2>{}
coll.Add(retUser);
}
</FONT><FONT color=#0000ff size=2>return</FONT><FONT size=2> coll;
}
</FONT>
-
unk ?
That doesn't even compile because of the continue and the catch blocks without exception types...
How on earth did that even get to the customer ?
-
It compiles. Not even a warning. :/
No idea how it got to the customer... I am going on-site tomorrow to clean up the mess. I hope things will work or I'll be quite ashamed myself.
-
@Goldie said:
unk ?
That doesn't even compile because of the continue and the catch blocks without exception types...
How on earth did that even get to the customer ?
It's C#, not Java.
-
Oh Dear God!!!. I do not envy you. I'd rather be wrapped in tin foil and stuck in a giant microwave for 20 minutes, than deal with that mess. My Sympathies.
-
<FONT size=2>Yes, it sucks badly. :( Here's one more funny thing among lots of others.</FONT>
<FONT color=#008000 size=2>//TODO: Fixa denna på något sätt (means: Fix this somehow)
</FONT><FONT color=#0000ff size=2>protected</FONT><FONT size=2> </FONT><FONT color=#2b91af size=2>PageDataCollection</FONT><FONT size=2> CurrentNewsList
{
</FONT><FONT color=#0000ff size=2>get</FONT><FONT size=2>{</FONT><FONT color=#0000ff size=2>return</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#2b91af size=2>PageDataCollection</FONT><FONT size=2>();}
}</FONT>It's not even built!
<FONT size=2>Not to mention anything that accepts user input is vulnerable to SQL injection. Locks everywhere without any reason since it's single-threaded. Caches user information when logged in without any reason. Functions and properties stuffed into any source file without any architectural thought at all. Username when logged stored as cookie, etc...</FONT>
<FONT size=2></FONT><FONT size=2>YAAAAAAR!! :(
</FONT>
-
That's a very interesting way of simulating the On Error Resume Next-statement in VB. Nice!
-
Hah! Better error message:
Parameter is of type parameter; cannot be parameter.