Skip to content

Files

Latest commit

 

History

History
30 lines (18 loc) · 1.14 KB

reading201-9.md

File metadata and controls

30 lines (18 loc) · 1.14 KB

Error

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.

ORDER OF EXECUTION

EXECUT.ION CONTEXTS

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

Error objects can help you find where your mistakes are and browsers have tools to help you read them.

HOW TO DEAL WITH ERRORS

  • DEBUG THE SCRIPT TO FIX ERRORS
  • HANDLE ERRORS GRACEFULLY

HOW TO LOOK AT ERRORS IN CHROME

The console will show you when there is an error in your JavaScript. It also displays the line where it became a problem for the interpreter.

BREAKPOINTS

You can pause the execution of a script on any line using breakpoints. Then you can check the values stored in variables at that point in time.

DEBUGGER KEYWORD

HANDLING EXCEPTIONS

If you know your code might fail, use try, catch, and finally.

Each one is given its own code block.

  • TRY, CATCH, FINALLY