reading-notes

Error Handling & Debugging

JavaScript can be hard to learn and everyone makes mistakes when writing it. This chapter will help you learn how to find the errors in your code. It will also teach you how to write scripts that deal with potential errors gracefully.

Execution Contexts

The JavaScript interpreter uses the concept of execution contexts. There is one global execution context; plus, each function creates a new new execution context. They correspond to variable scope.

Understanding Errors

If a JavaScript statement generates an error, then it throws an exception. At that point, the interpreter stops and looks for exception-handl ing code.

How to Deal with Erros

1- Debug the script to fix errors. 2- Handel errors gracefully

Throwing Errors

If you know something might cause a problem for your script, you can generate your own errors before the interpreter creates them.