ecometer

Avoid using try...catch...finally

(Development)
#30

Avoid calls to try…catch..finally in resource-heavy areas of code (some loops, generation of complex data, etc.). When an exception is thrown, a variable (the exception itself) is created at the start of the catch clause and destroyed at the end. Creating and destroying this variable unnecessarily uses CPU power and RAM. Hence why it is important to replace this construction with a logic test as often as possible.

Favor a logic test:

var oProperties = ['first','second',...,'nth'], i;
try {
    for( i = 0; i < oProperties.length; i++ ) { 
        test[oProperties[i]].someproperty = somevalue;
    }
} catch(e) {
    ...
}

Further reading:
http://dev.opera.com/articles/view/efficient-javascript/?page=2#trycatch