Error Handling in JavaScript
Error Handling = how to handle problems calmly and find bugs fast.
This chapter has 2 lessons and 8 exercises you run and check in your browser. Plan on about 49 minutes.
- Error and Exception Handling:
try,catch,finally,throwand the error types. - Debugging: the console, breakpoints, stack traces and the common bugs.
After this chapter, you can:
- Tell syntax, runtime and logical errors apart.
- Keep a program running with
try,catchandfinally. - Throw clear errors of your own.
- Find the real cause of a bug from the console and the stack trace.
Every lesson has short explanations, code boxes you edit and run in the live editor, and a web page example you can click.
Before you start, finish Data Handling.
Next chapter: Async Concepts.
Lessons in this section
- Error and Exception Handling
What an error is, the three kinds of error, and how exceptions work, then try, catch and finally, throwing your own errors with clear messages, the error object, the built-in error types and handling JSON.parse() failures.
- Tell a syntax error, a runtime error and a logical error apart
- Explain what an exception is and how it differs from an error
- Use try, catch and finally to handle a failure and always clean up
- Throw an Error with a message that says what went wrong
- Debugging
What debugging is and why it matters, console debugging with log, error, warn and table, breakpoints and stepping in DevTools, watching variables and inspecting scope, reading a stack trace, and fixing the most common beginner bugs.
- Explain what debugging is and why looking at values beats guessing
- Use console.log, console.error and console.warn, and know when console.table helps
- Set a breakpoint in DevTools or with debugger and step through code
- Watch variable values and inspect the scopes a paused line can see