Error handling and debugging

Error Objects

There are seven main types of built-it error objects in JS:

  1. Error: generic error
  2. SyntaxError: the proper syntax is not followed
  3. ReferenceError: referencing a variable that is either undeclared or not within scope
  4. TypeError: using an unexpected data type
  5. RangeError: numbers are not in the specified range
  6. URIError: URI related methods are used incorrectly
  7. EvalError: eval() function used incorrectly

Dealing with Errors:

In order to deal with errors, there are two routs you may choose one based on what is best suited for the situation.

Debug the script

This basically is using developer tools available to you, to track down an error after it occurs and resolving it. To do so, you must find where the problem is; console allows you to find where the script breaks and helps you determine where to look for the problem.

Handle errors gracefully

UNDERSTANDING ERRORS

CONDITIONAL BREAKPOINTS

5 JavaScript Debugging Tips:

  1. Debugger statement
  2. Using the console in the debugger
  3. Conditional breakpoints
  4. Async traces
  5. Pause on exceptions

Note


Table Of Content