Error Handling Programs

Try Catch With Confirm Box Program


<!DOCTYPE html>
<html>
<head>
<script>
  var txt = "";

  function message() {

    try {

      adddlert("Welcome guest!");

    } catch (err) {

      txt = "There was an error on this page.\n\n";
      txt += "Click OK to continue viewing this page,\n";
      txt += "or Cancel to return to the home page.\n\n";

      if (!confirm(txt)) {
        //action on confirm
      }
    }
  }
</script>
</head>

<body>
<input type="button" value="View message" onclick="message()" />
</body>

</html>