Exceptional Assignment

Exceptional Assignment

Ellen sends us a very simple WTF today, that she found in production code.

bool condition;

try
{
    condition = true;
}
catch
{
    condition = false;
}

It’s true, there isn’t much to say about this exceptional code block. But if assigning a boolean to a boolean variable ever fails, we’re prepared to handle it.

Remy Porter

Source link