0

Is there a way to console(.)error an error without it stopping the code. Like a global try/catch

1
  • 1
    console.error doesn't stop code Commented Sep 5, 2021 at 13:54

2 Answers 2

1

You can use the window.onerror event handler as a global event handler and write something like:

window.onerror = function myErrorHandler(error, url, lineNumber) {
  logger("error has occured = " + error);
  return false;
}

you can read more about it here:

https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror

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

1 Comment

This is for web.
0

If you just want to continue, there's try-catch-finally:

try {
  tryCode - Block of code to try
}
catch(err) {
  catchCode - Block of code to handle errors
}
finally {
  finallyCode - Block of code to be executed regardless of the try / catch result
}

Comments

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.