0 points

Handle Javascript errors with try-catch, throw and finally


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) {
finally {
  alert('thanks for playing!');
content_copy 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