<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Error Handling</title>
</head>
<body>
  <h2>Error Handling</h2>

  <p id="demo"></p>
  
  <script>
    
  try {
    alerted("Welcome guest!"); // Deliberate error
  }
  catch(err) {
    document.getElementById("demo").innerHTML = err.message;
    
  }
  finally {
    console.log("This code runs regardless of errors.");
  }
    
   // throw new Error("This is a custom error message 123");
    
 </script>
</body>
</html>
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.