Frontory

Open code, practice, and notes →

Download source with English comments · for reading

JavaScript · 10 Exceptions and Recovery Paths

Series contents · Technology map

Stage: DOM and asynchronous operations · Editable example · Storage ID: javascript-step-10

Goals and learning outcomes

Prerequisites

The work and experiment records from Unit 9, “Map and Set Indexes”

Key concepts and explanations

Exception Propagation

throw transfers control to the nearest catch. In catch, recover or add context and pass the exception on.

Guaranteed Cleanup

finally runs after success and failure. A return here can override the original return value or exception.

Practice setup

First check the execution scope guidance on the example screen. The following environment is for extending the assignment in a separate project. Implement it yourself in a separate local project and check it with browser developer tools. In a separate folder, connect your practice JS from index.html using script type="module" and open it through a local HTTP server. Use the Console, Network, and Elements panels.

The linked example is a starting point. It does not implement every task below. Complete work beyond its supported scope in a separate project.

Practice tasks

  1. In parse.js, prepare valid JSON and JSON with a missing closing bracket.
  2. Wrap JSON.parse in try/catch and turn off the progress indicator in finally.
  3. Run with valid JSON and JSON with a missing closing bracket. Results to check: The busy state ends after both success and failure. Read valid input again after a failure. Record expected and actual results separately.

Variables to observe

VariableBaselineChangeExpected change / hypothesis
JSONValidMissing bracketHypothesis before running: The progress indicator will turn off after the failure message. Keep the other conditions fixed and record the actual result separately after running.

Predictions in this table are not measured results. Change one condition at a time and record why the actual result differs.

Completion criteria

Self-check

  1. What information does an empty catch lose?
  2. Why must you be careful with return in finally?

Official references

Linked example and execution scope

Example source · Runtime environments and limits

Compare the editable inputs with actual browser execution results.

Source code and records are not overwritten automatically. Resetting an existing example also preserves your notes.

Next learning

Previous: Map and Set Indexes · Next: Creating DOM Nodes and Inserting Text

Open code, practice, and notes →