Skip to content
Computer Science · 11th Grade

Active learning ideas

Error Handling and Exceptions

Active learning works for error handling because students need to experience the disruptive nature of exceptions firsthand. When they see a crash caused by their own code, they better understand why handling errors is essential for reliability and user trust.

Common Core State StandardsCSTA: 3B-AP-16
25–40 minPairs → Whole Class3 activities

Activity 01

Problem-Based Learning35 min · Pairs

Debug It: Find and Fix the Exception

Provide five short code samples, each with a different unhandled runtime exception (NullPointerException, ArrayIndexOutOfBoundsException, NumberFormatException, FileNotFoundException, StackOverflowError). Students individually identify the exception type, explain what triggers it, and add appropriate error handling. Pairs compare their solutions and discuss differences in approach.

Explain the importance of error handling in creating reliable software.

Facilitation TipDuring Debug It, have students work in pairs to trace the stack trace line by line before writing any fixes.

What to look forPresent students with short code snippets in Java or Python that contain common runtime errors (e.g., division by zero, index out of bounds). Ask them to identify the error, predict the output if unhandled, and then write the correct try-catch or try-except block to handle it.

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 02

Problem-Based Learning40 min · Small Groups

Design Challenge: Crash-Proof the Calculator

Groups receive a simple command-line calculator that crashes on invalid input, division by zero, and non-numeric entries. Their task is to add complete error handling that gives users informative messages and allows the program to continue running. Groups then exchange code and test each other's implementations by attempting to crash them.

Analyze different types of errors (compile-time, runtime, logical) and how to address them.

Facilitation TipDuring Design Challenge, require students to create user-friendly error messages, not just silent catches.

What to look forPose the scenario: 'Imagine you are building a simple text editor. What are three potential runtime errors a user might encounter (e.g., trying to save to a read-only location, opening a corrupted file)? How would you use exception handling to inform the user and prevent a crash?'

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 03

Gallery Walk25 min · Small Groups

Gallery Walk: Error Type Classification

Post six code snippets around the room, each with a specific error type (compile-time, runtime, or logical). Students rotate, classify each error type, and write what information would help diagnose and fix the problem. Debrief on the logical errors--which are hardest to detect and why.

Design a strategy for handling exceptions in a given program to prevent crashes.

Facilitation TipDuring Gallery Walk, ask students to classify exceptions by their source (input, logic, I/O) as well as their type.

What to look forProvide students with a program that simulates reading user input for an age. Ask them to write one try-except block in Python (or try-catch in Java) that specifically handles `ValueError` if the user enters non-numeric input, prompting them to re-enter a valid age.

UnderstandApplyAnalyzeCreateRelationship SkillsSocial Awareness
Generate Complete Lesson

A few notes on teaching this unit

Teach error handling by starting with real failures—show students a program crash and ask them to diagnose it. Avoid beginning with syntax rules; instead, focus on the mindset of anticipating failure. Research shows that students grasp exception handling better when they see it as a communication tool between parts of a program rather than just a technical fix.

Successful learning looks like students confidently identifying exceptions, writing targeted handlers, and explaining why specific error types require specific responses. They should also articulate the risks of broad exception handling, demonstrating a shift from defensive to deliberate programming.


Watch Out for These Misconceptions

  • During Design Challenge: Crash-Proof the Calculator, watch for students using a single broad catch block to handle all exceptions in their calculator code.

    Redirect students to the Calculator Design Spec sheet that explicitly asks them to handle at least three specific exceptions (e.g., division by zero, invalid input types, empty memory). Encourage them to document why each exception needs its own handler.

  • During Debug It: Find and Fix the Exception, watch for students assuming that catching an exception means the program runs without issues afterward.

    Have students run the corrected code to verify the program still fails in a different way. Use the debrief to discuss how exception handling prevents crashes but does not fix the root cause of the error.

  • During Gallery Walk: Error Type Classification, watch for students grouping exceptions only by their names (e.g., ValueError, FileNotFoundError) without considering their source.

    Provide the Error Type Classification worksheet with a column for source categories (user input, file operations, logic errors). Ask students to relabel their groups based on these categories during the walk.


Methods used in this brief