Exceptions and Error Handling
- Throwing. A throw statement raises an Error, abandoning normal flow until something catches it.
- try/catch. A try block runs risky code; its catch receives the thrown error so the program answers instead of dying.
- finally. The finally block runs whether the try succeeded or threw: the place to release what you opened.
Debuggers and Stack Traces
- Stack traces. A stack trace lists the calls in flight when an error was thrown: read it top-down to find your own file first.
- Breakpoints. A breakpoint pauses the program on a chosen line so you inspect real variable values instead of guessing.
- Stepping. Stepping runs the paused program one line at a time, showing exactly where reality diverges from your mental model.
Defensive JavaScript
- Validating inputs. Check inputs at the boundary: the function that receives outside data: so bad values fail loudly and early.
- Failing honestly. Throw with a message that names what was expected and what arrived; “something went wrong” helps nobody at 2am.
- Error types. Distinguish expected failures you handle from programmer bugs you want loud: never blanket-catch and continue silently.
Before and after this level
- Before: Level 7: Modules & Code Organisation: ES Modules, Imports, Exports and Dependencies, Designing Maintainable Modules.
- Next: Level 9: Asynchronous JavaScript: Event Loop and Task Scheduling, Promises and async/await, Concurrent Asynchronous Work.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does JavaScript Level 8: Errors & Debugging cover?
Exceptions and Error Handling, Debuggers and Stack Traces, Defensive JavaScript: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 7: Modules & Code Organisation, which covers ES Modules, Imports, Exports and Dependencies, Designing Maintainable Modules.