1

There are 2 scripts on the page. If the first one causes an error, then the second refuse to work because of this.

How do I make the second script turn a blind eye to the first one's errors and work anyway? Keep in mind that I'm not allowed to change the first script.

2
  • 1
    Show your problematic code and errors. Separate scripts shouldn't have any problems with each other unless second tries to use data that were supposed to be initialized in first. Commented Jan 25, 2013 at 11:20
  • won't a simple try/catch solve this issue? Commented Jan 25, 2013 at 11:20

3 Answers 3

4

Maybe this might help

<script type="text/javascript">
    function stoperror()
    {
        return true;
    }
    window.onerror=stoperror();
</script>

MOZILLA DEVELOPER NETWORK window.onerror

Sign up to request clarification or add additional context in comments.

Comments

2

Javascript execution stops when the error occurs...

You can not change this behavior...

To get around, put the code that causes an error inside try block

try{
    //code that might produce some error
} catch(e){
}

Comments

2

I would use try and catch blocks, and disregard any error.

That should work..

Example

try
{
    //Run some code here
}
catch(err)
{
    //Handle errors here
}

3 Comments

Right! (+1)... If there is an error and exception is not thrown, that would mean you have syntax error
Not necessarily syntax error. Any error that is not a thrown exception will still be an error. E.g. somevar.somefunc() if somevar is undefined, null, etc.. catch will only be entered if throw was issued during execution.
in any case, whether your catch block gets fired or not, try will avoid script from crashing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.