Assert method : assert « Development « JavaScript Tutorial






<html>
<head>
<title>Debug Example</title>
<script type="text/javascript">
  function assert(bCondition, sErrorMessage) {
      if (!bCondition) {
          alert(sErrorMessage);
          throw new Error(sErrorMessage);
      }
  }


  function aFunction(i) {
      assert(false, "1==2");
  }

  aFunction(1);


</script>
</head>
<body>
    <P>This page uses assertions to throw a custom JavaScript error.</p>
</body>
</html>








4.1.assert
4.1.1.Assert method
4.1.2.Catch exception throwed from assert function