Skip to content
Computer Science · Grade 9

Active learning ideas

Debugging and Error Handling

Debugging and error handling require hands-on practice because students must experience the frustration of errors to understand why systematic approaches work. Active learning through collaborative and iterative tasks builds resilience and confidence, turning debugging from a guessing game into a structured problem-solving skill.

Ontario Curriculum ExpectationsCS.HS.AP.4CS.HS.CT.5
20–45 minPairs → Whole Class4 activities

Activity 01

Problem-Based Learning30 min · Pairs

Pairs: Buggy Code Relay

Pairs get code with 3-5 deliberate errors. One partner traces execution aloud while the other notes issues; they switch to propose and test fixes using print statements. Document the process in a shared log before verifying with sample inputs.

Differentiate between syntax errors and logical errors in code.

Facilitation TipFor Buggy Code Relay, provide each pair with a different buggy snippet and a timer to keep the relay moving, ensuring all students engage in rapid, focused debugging.

What to look forPresent students with two code snippets, one with a syntax error and one with a logical error. Ask them to identify which is which and explain the difference in their own words. For example: 'Snippet A has a missing semicolon. Snippet B calculates the average incorrectly. Which is a syntax error and why?'

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 02

Problem-Based Learning45 min · Small Groups

Small Groups: Algorithm Debug Stations

Set up 4 stations with pseudocode or flowcharts containing syntax or logic errors. Groups spend 8 minutes per station: identify error type, fix it, test with 3 inputs, and explain to the next group. Rotate and compare fixes.

Design a systematic approach to debugging a faulty algorithm.

Facilitation TipDuring Algorithm Debug Stations, set up each station with a unique error type and require groups to document their findings on a shared tracking sheet before rotating.

What to look forProvide pairs of students with a short, buggy algorithm. One student identifies a potential error and proposes a fix, explaining their reasoning. The other student reviews the proposed fix, checks if it resolves the issue without introducing new ones, and provides feedback. 'Does your partner's fix address the error? Does it create any new problems?'

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 03

Problem-Based Learning25 min · Whole Class

Whole Class: Error Prediction Challenge

Display a faulty program on screen. Class predicts outputs for given inputs, then runs it to reveal discrepancies. Discuss as a group, vote on fixes, test top ideas, and refine based on results.

Justify the importance of thorough testing in the development process.

Facilitation TipFor the Error Prediction Challenge, ask students to vote on the most likely error type before running the code, then compare predictions to actual outcomes to highlight gaps in reasoning.

What to look forAsk students to describe a systematic approach they would use to debug a program that is not producing the correct output. Prompt them to include at least two specific steps or strategies. For instance: 'Outline your debugging process for a program that should sort numbers but is returning them in the wrong order.'

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 04

Problem-Based Learning20 min · Individual

Individual: Debug Journal Practice

Students select a past algorithm, reproduce an error with new inputs, apply a checklist (trace, isolate, test), fix it, and journal steps with before-after screenshots.

Differentiate between syntax errors and logical errors in code.

What to look forPresent students with two code snippets, one with a syntax error and one with a logical error. Ask them to identify which is which and explain the difference in their own words. For example: 'Snippet A has a missing semicolon. Snippet B calculates the average incorrectly. Which is a syntax error and why?'

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
Generate Complete Lesson

A few notes on teaching this unit

Teachers should model debugging aloud, thinking through their own errors in real time to normalize mistakes and reduce frustration. Avoid rushing to provide fixes; instead, guide students with questions like 'What did you expect this line to do?' or 'How could you test if this variable holds the right value?' Research shows that students who verbalize their reasoning while debugging develop stronger metacognitive skills.

By the end of these activities, students will confidently distinguish between syntax and logic errors, apply step-by-step debugging methods, and justify their fixes with evidence. They will also recognize that thorough testing is essential to uncover hidden flaws before code reaches users.


Watch Out for These Misconceptions

  • During Buggy Code Relay, watch for students making random changes to code without tracing its execution or testing inputs.

    Pause the relay and ask partners to trace one line at a time together, recording variable values after each step to identify where the output first deviates from expectations.

  • During Algorithm Debug Stations, watch for students assuming logical errors are minor and only fixing syntax to 'make it run'.

    Require groups to test their fixed code with at least three different inputs, including edge cases, and justify why their solution addresses the logic flaw rather than just the syntax.

  • During Error Prediction Challenge, watch for students dismissing logical errors because the code runs without crashing.

    After the vote, run the code with predicted inputs and ask students to compare outcomes to their predictions, prompting them to re-evaluate whether 'running code' equals 'correct code'.


Methods used in this brief