Html code on a screen

Try catching this!


Sometimes software engineering is like herding cats with a dog into a box.. at sea..?

As a software engineer, after some time it becomes second nature to 'just write code', this is great for prototyping an idea or creating a proof of concept, but when it comes to production code, standards are key. Keep it neat, tidy, minimal and to coding standards and above all, remove that pointless code. 

One of the most common things I see is this;

try {
    something();
} catch {
   // do nothing.
}

Ok, so that is all and good, but whats the point of the catch. Now I know there are several arguments out there about the fact the comment IS the code, but I disagree. If you are going to catch something, you might as well do something with it. My approach in these cases is usually something like this;

try { 
    something(); 
} catch(Exeption $ex) { 
    Log($ex->message()); 
}

Even if this approach logs out thousands of messages it proves the point that if trying something is consistently failing perhaps the logic process needs rethinking, try and catch are after all only suppose to be used if you think there is a possibility of failure NOT a likelihood.

I tend to go by the rule that if something will error out 2 out of 5 then you need to design a system to expect that and react to it, not just throw it in a try catch scenario.