If at first you don’t succeed…

26 11 2010

Today I came across one of the most Daily WTF worthy pieces of code I’ve seen in a long time:

    void SomeFunction()
    {
        try
        {
            try
            {
                /* Slightly more than 50 lines of code
                 * some of which contain additional
                 * try/catch blocks
                 */
            }
            catch (Exception) { }
        }
        catch (Exception ex)
        {
            Debug.Assert(false, ex.Message);
        }
    }

The consensus among the people I showed this to was that the inner try was added in order to solve an assert (I think this opinion was only mostly tongue in cheek…). In fact, since very few people use the debug build, both catch blocks are equivalent.

Unfortunately due to the fact that we’ve recently changed source control systems and that dos2unix was used at some point in the past the culprit will probably remain anonymous.








Follow

Get every new post delivered to your Inbox.