Home›Lesson Plans›Computer Science›Program Development · Grade 10

Error Handling

Tenth graders write robust programs that do not crash on bad input. Risky code goes in a try block; if it fails, an except block catches the error and recovers gracefully. They sort what goes in try vs except, then add error handling to a program.

Grade 10Error Handling (try / except)55 minutes1 class periodCSTA / ISTEExplicit teaching4 StandardsCSTA
Start the Lesson
Assign or share this lesson

Copy link works with Canvas, Schoology, Moodle and any other LMS — paste it in as a resource or assignment.

Lesson at a Glance

Everything you need before the bell rings

Learning Objectives

Students will be able to…

  • ✓Use try / except.
  • ✓Put risky code in try.
  • ✓Recover in except.
  • ✓Make a program robust.
Essential Question

How do you keep a program from crashing when something goes wrong?

0
Lesson Phases
0
Vocabulary Terms
0
Standards Aligned
0
Interactive Task
Sort It · Interactive

try Block or except Block?

Project this and sort each item into the try block (risky code) or the except block (handle the error).

🛡️ Sort each — does it go in try (risky) or except (handle it)?Try it
🧪 try (risky code)
🛟 except (handle it)
Tap an item, then tap a box.
The Lesson · Use → Modify → Create (a coding progression with Unplugged practice)

55 minutes, five moves

Tap any phase to open the teacher moves and student actions.

1

Hook — When It All Goes Wrong

6 min

What happens if a user types “cat” where a number is expected?

👩‍🏫 Teacher Moves

  • Show a program crashing.
  • Ask how to prevent it.
  • Set the goal.

🎒 Student Actions

  • Look.
  • Guess.
  • Get ready.
2

Use — Error Handling

13 min

Students use the idea.

👩‍🏫 Teacher Moves

  • Send students to try or except?
  • Sort each item.
  • Note risky code vs recovery.

🎒 Student Actions

  • Sort.
  • Say.
  • Note it.
3

Modify — Catch It

14 min

Students modify.

👩‍🏫 Teacher Moves

  • Wrap risky code in a try.
  • Add an except to recover.
  • Test a bad input.

🎒 Student Actions

  • Wrap.
  • Add.
  • Test.
4

Create — Make It Robust

15 min

Students create.

👩‍🏫 Teacher Moves

  • Add try/except to a program.
  • Give a friendly message.
  • Use a safe default.

🎒 Student Actions

  • Add.
  • Message.
  • Default.
5

Reflect — Reflect

7 min

Students close.

👩‍🏫 Teacher Moves

  • Say what goes in try.
  • Say what except does.
  • Complete the exit ticket.

🎒 Student Actions

  • Say it.
  • Say.
  • Complete the exit ticket.
Standards Alignment

Built to the standards you report on

Aligned to the CSTA K-12 Computer Science Standards and the ISTE Standards for Students.

CSTA
3A-AP-21

Evaluate and refine artifacts for correctness and robustness.

CSTA
3A-AP-17

Decompose problems into components.

CSTA
3A-AP-15

Iteratively develop programs using control structures.

ISTE
5 Computational Thinker

Test for and handle edge cases.

Differentiation

One lesson, every learner

Multilingual Learners

ELL / EMERGING READERS
  • Act out “try, then catch.”
  • Frame: “risky here, recover there.”
  • Pair talk first.

Support & Access

IEP / 504
  • Sort try vs except only.
  • Wrap one risky line.
  • Use a template.

Stretch & Extend

GIFTED / EARLY FINISHERS
  • Catch specific error types.
  • Add a finally block.
  • Validate input before trying.
Materials

What to gather

  • 📽️Screen / board
  • 🛡️try/except cards
  • 💻try or except?
  • 🐍Python / editor
  • 📓Notebooks
  • 🎫Exit-ticket slips
Vocabulary

Key terms — hover for a quick definition

error / exceptiona problem that interrupts a programtryblock holding code that might failexceptblock that runs if the try failscatchto handle an error instead of crashingrobustkeeps working on bad inputcrashthe program stops with an errordefaulta safe fallback valuevalidatecheck input before using it
Evaluate

Exit Ticket

Preview the three formative checks. Tap “Sample answer” to see what mastery looks like — hide them before you print for students.

QUESTION 1
What goes in a try block?
Risky code that might fail.
QUESTION 2
What does an except block do?
Catches the error and recovers gracefully.
QUESTION 3
Why handle errors?
So the program does not crash on bad input.

Reflect: error handling.

Have students wrap one risky line in try/except with a friendly message. A printable error-handling worksheet is in the Computer Science library.

Study · Flashcards

Study the key terms

Tap a card to flip it, then rate whether you knew it. Built from this lesson’s vocabulary.

🃏 CS Error Handling (Grade 10)Flip
Card 1
Term
Tap to flip →
Meaning
0

Nice work!

Practice · Quiz

Check your understanding

A quick self-check with instant feedback, drawn from this lesson’s key terms.

📝 CS Error Handling (Grade 10)Quiz
Score: 0
1 / 6
Question 1
0%

Nice work!

Practice · Worksheet

Printable worksheet

A print-and-go review sheet with a built-in answer key. Tap “Show answer key” to reveal answers, or print the clean version for students.

🖨️ CS Error Handling (Grade 10)Print
Name: ________________________
Date: ____________

Part A · Write the word that matches each meaning

Word bank: catch, crash, default, error / exception, except, robust, try, validate
  1. to handle an error instead of crashing
  2. block holding code that might fail
  3. check input before using it
  4. a safe fallback value
  5. block that runs if the try fails
  6. keeps working on bad input
  7. the program stops with an error
  8. a problem that interrupts a program

Part B · Show what you learned

  1. What goes in a try block?
  2. What does an except block do?
  3. Why handle errors?
Answer key — Part A: 1) catch · 2) try · 3) validate · 4) default · 5) except · 6) robust · 7) crash · 8) error / exception
Part B: 1) Risky code that might fail. 2) Catches the error and recovers gracefully. 3) So the program does not crash on bad input.