Page 163 - CITS - Computer Software Application -TT
P. 163

COMPUTER SOFTWARE APPLICATION - CITS




               Error Name                                       Description

               EvalError                                        An error has occurred in the eval() function

               RangeError                                       A number “out of range” has occurred
               ReferenceError                                   An illegal reference has occurred

               SyntaxError                                      A syntax error has occurred

               TypeError                                        A type error has occurred
               URIError                                         An error in encodeURI() has occurred

           The six different values are described below.
           Eval Error
           An EvalError indicates an error in the eval() function.

           Newer versions of JavaScript do not throw EvalError. Use SyntaxError instead.
           Range Error
           A RangeError is thrown if you use a number that is outside the range of legal values.
           For example: You cannot set the number of significant digits of a number to 500.
           Example

           let num = 1;
           try {
             num.toPrecision(500);   // A number cannot have 500 significant digits
           }

           catch(err) {
             document.getElementById(“demo”).innerHTML = err.name;
           }
           Reference Error
           A ReferenceError is thrown if you use (reference) a variable that has not been declared:
           Example

           let x = 5;
           try {
             x = y + 1;   // y cannot be used (referenced)
           }
           catch(err) {
             document.getElementById(“demo”).innerHTML = err.name;
           }
           Syntax Error
           A SyntaxError is thrown if you try to evaluate code with a syntax error.
           Example
           try {

             eval(“alert(‘Hello)”);   // Missing ‘ will produce an error
           }



                                                           150

                             CITS : IT&ITES - Computer  Software Application - Lesson 37 - 46
   158   159   160   161   162   163   164   165   166   167   168