0 points

Handle Javascript errors with try-catch, throw and finally


dashboard

Wed Jan 01 2020 19:00:00 GMT+0000 (UTC)

Posted by @new_roman11 #javascript #errors #howto

try {
  let hello = prompt("Type hello");
  if (hello !== 'hello'){
    throw new Error("Oops, you didn't type hello");
  }
}
catch(e) {
  alert(e.message);
}
finally {
  alert('thanks for playing!');
}
content_copy

try — code to try that may produce errors catch — code that will handle any errors throw — a keyword you can use to throw your own custom errors finally — code that will run after a try/catch block regardless of the outcome

https://codeburst.io/learn-how-to-handle-javascript-errors-with-try-throw-catch-finally-83b4f9ef8c6f

>> Browse more code snippets

more_vert