Archive for the ‘Inspirational code’ Category.

If at first you don’t succeed, try try (catch catch) again

So I am cruising through the ASP.NET C# MVP web project we are working on, and happened upon this method (again, the names were changed to protect the not so innocent):

private void mView_LoadObjects(object sender, EventArgs e)
{
    try
    {
        try
        {
            BusinessLayer.Class1 bizClass = new BusinessLayer.Class1();
            mView.objects = bizClass.GetObjects(mView.ID1, mView.ID2);
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(ex.Message);
            throw;
        }
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine(ex.Message);
        throw;
    }
}

However, the fun didn’t stop there.  A little further down the class, I found this:

private void mView_LoadOtherObjects(object sender, EventArgs e)
{
    try
    {
 
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine(ex.Message);
        throw;
    }
}

I am thinking that the catch block on this second example was not hit very often.

Brought to you by The Department Of Unnecessary Code

Another nicety that I happened upon, this time from the C# realm. The names were changed to protect the innocent.

theClass.uniqueID = (id != null) ? id : null;

Looks like someone just figured out how to use the ternary operator and was determined to use it.

Yet another software development blog

One thing that the internet doesn’t really need is a zillion and one software development blogs, one zillion software development blogs is just the right number.

However, I stumbled upon this Visual Basic .NET nugget at work one day and just couldn’t resist…

Private Function getCustomers() As Array
 
    'do something here
 
End Function

This blog is in honor of my discovery. Please stay tuned for lots more nuggets o’ gold, random thoughts, and sometimes maybe even problems I have run across and how they were solved.