← JavaScript

Error Handling – try/catch

Runs code in a try block, and if an error occurs, runs the catch block instead of crashing.

Understanding Error Handling – try/catch in JavaScript

What it does: Errors in try are caught instead of stopping the whole program. The catch parameter stores details about what went wrong. The catch block runs instead of the program crashing. If no error occurs, the catch block is simply skipped. JavaScript is case-sensitive, so 'try' must be lowercase.

Common mistakes: 'try' must be lowercase - a capital T causes an error. 'console' is misspelled as 'consol'.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 41–52) and word search (Modules 21–52).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Does try/catch let a program keep running after an error?
YesNo
Matches
Try { console.log(x); } catch (e) {}
↓
Wrong - 'try' must be lowercase
Applying
Meanings
Term
try...catch
Meaning
Runs code in a try block, and if an error occurs, runs the catch block instead of crashing.
Practice
try {
Testing
Gaps
{
Check Answer
Spots
1Try {
2console.log(a);

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Arctic Fox' badge — Tundra Tracker, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Does try/catch let a program keep running after an error?
A. Yes ✓
B. No
The catch block runs instead of the program crashing.
2. Does the catch block run only when an error occurs in try?
A. No
B. Yes ✓
If no error occurs, the catch block is simply skipped.
3. Must 'try' be written in lowercase?
A. Yes ✓
B. No
JavaScript is case-sensitive, so 'try' must be lowercase.
4. Must 'catch' be written in lowercase?
A. Yes ✓
B. No
JavaScript is case-sensitive, so 'catch' must be lowercase.
5. Does catch's parameter hold information about the error?
A. No
B. Yes ✓
The parameter, like e or error, stores details about what went wrong.

Match the Pairs

try { risky(); } catch (e) { ... } → Runs the try block, and if it errors, runs catch
catch (e) { console.log(e); } → Runs this block only if an error occurred in try
Prevents a program from crashing when an error occurs → try { risky(); } catch (e) {}
Holds information about the error inside catch → e
Try { console.log(x); } catch (e) {} → Wrong - 'try' must be lowercase
try { console.log(x); } Catch (e) {} → Wrong - 'catch' must be lowercase

Key Term

try...catch
Runs code in a try block, and if an error occurs, runs the catch block instead of crashing.

Fill in the Blanks

1. try { console.log(risky); } catch (e) { }
Hint: Type the keyword that starts the block of code to attempt.
2. try { doSomething(); } catch (e) { console.log(e); }
Hint: Type the keyword that runs its block only if an error occurs.
3. try { parseData(); } catch (err) { }
Hint: Type the parameter name that holds the error.
4. try { loadFile(); } catch (problem) { }
Hint: Type the keyword that starts the block of code to attempt.
5. try { connect(); } catch (problem) { console.log(problem); }
Hint: Type the keyword that runs its block only if an error occurs.

Spot the Error

Question 1
A Try {
B console.log(a);
C } catch (e) {
D }
Line A — 'try' must be lowercase - a capital T causes an error.
Question 2
A try {
B consol.log(b);
C } catch (e) {
D }
Line B — 'console' is misspelled as 'consol'.
Question 3
A try {
B console.log(c);
C } Catch (e) {
D }
Line C — 'catch' must be lowercase - a capital C causes an error.
Question 4
A try {
B console.log(d);
C } catch (e) {
D console.log(e)
E }
Line D — This line is missing a semicolon, but that's not required in JS.
Question 5
A try {
B console.log(g);
C } catch (e) {
D console.log(e);
E }}
Line E — There's an extra closing brace - only one } is needed here.

Student with a class code? Join your class →