Possible Duplicate:
How to catch exceptions in javascript?
I am changing old web application. Unfortunately to some of layout changes is generated components I didn’t find any reasonable solution, so I was forced to use ‘javascript hacks’. My template on the end of loading page load javascript file ‘layoutfixes.js’ that change some generated components. Generated commponents have various Ids or do not ha them at all, so sometime I had to obtain element in terrible way, like this:
var tdNodes = document.getElementById('tabbedPanel').childNodes[1].childNodes[0]. ... .childNodes[0];
But as I said not every page has those components, so lines as above throw error that element is null. I do not what add everywhere checking if there exist such element on page or not. I whould perfer add something like “try{} catch(Exception e){}” in that javascript. But I am not familar with javascript enough. Is in javascript something like that?
Hack is the right word for what you are doing there. As you are already well into the world of hackery you might as well add another with a try/catch:
More info here: http://www.w3schools.com/js/js_errors.asp