in

Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, and other Microsoft products, as well as some discussion of general programming related concepts.

Not Necessarily Dot Net

February 2008 - Posts

  • Empty try/catch blocks

    I've seen several people do this, and it's always been a big clue to me that they're very new and inexperienced with .net. There are a few variations.

    try
    {
        blah;
    }
    catch
    {}

    That's probably the absolute worst. Your exception disappears completely, and no one ever knows it happened. I'm sure there are times it's actually the right thing to do, but it's almost always just a big red flag that whoever wrote the code was either in an unforgivable hurry or completely clueless. If nothing else, there should be a comment about why it was done that way.

    Another version that one of my co-workers likes goes

    try
    {
       blah;
    }
    catch (Exception e)
    {
        throw;
    }

    Maybe he just puts it there in case something wrong turns up later, and he has the framework in place so he won't have to add it later, if he does decide to actually handle an error there. Someday I really do have to ask him about it. Maybe he knows something I don't.

2015 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems