I am writing a Windows Sidebar Gadget using JavaScript. Now I would like to have all JavaScript exceptions caught and logged to a text file. One problem is that when an exception is thrown at any line, the next line will not be executed. Is it possible to catch exceptions automatically so that the following line of JavaScript can be executed.
Here is the sample code which demonstrates my problem:
try
{
alert(document.getElementById("non-existing-element").value);
}
catch(ex)
{
}
alert("This is shown.");
alert(document.getElementById("non-existing-element").value);
alert("This is not shown.");
So one big try-catch-method whould allow to log the error but the rest of the code would not be executed.
One solution would be to catch errors for every line. But would be too much code for several thousand lines. (or I write a macro which does this for me)
Maybe anyone can help me.
Thank you.
Instead of trying to catch errors, you should be trying to build proper logic to control them.
But you are describing suppressing errors
You can suppress error in JavaScript with a onerror event handler.
More information here