IB Computer Science HL · Year 2 · Lesson 10

Exception handling, debugging, file processing + B2 Paper 2 checkpoint

Programming fundamentals turn algorithms into reliable executable procedures. Scope, data types, debugging and exceptions all affect correctness. File processing connects a program to persistent data and requires careful control of reading, writing and data validity.

Paper 250 minutesB2.1.3 · B2.1.4 · B2.5.1 · B2.1.1 · B2.1.2 · B2.2.1 · B2.2.2…
Today’s targets

What you need to be able to do

2 / 11
  • DescribeHow programs use common exception handling techniques
  • ConstructAnd use common debugging techniques
  • ConstructCode to perform file-processing operations
  • RetrieveReconnect today’s new material to previously taught content from this topic.
B2.1.3B2.1.4B2.5.1B2.1.1B2.1.2B2.2.1B2.2.2B2.2.3B2.2.4B2.3.1B2.3.2B2.3.3B2.3.4B2.4.1B2.4.2B2.4.3B2.4.4B2.4.5
Paper 2 lensMatch the depth of every response to the command term. Previously learned content can move quickly, but retrieval must still be accurate.
Retrieve

Rapid Recall Deck

3 / 11

Say the answer aloud before flipping. Mark secure knowledge quickly and spend time on the gaps.

  • Which three potential program-failure points must you recognize?: Unexpected inputs, resource unavailability, and logic errors.
  • What is the role of exception handling?: It allows a program to detect and respond to exceptional runtime conditions instead of failing unpredictably.
  • What is the purpose of a finally block or equivalent cleanup step?: To run cleanup code that should occur whether or not an exception is raised, such as closing a resource.
  • Which debugging techniques should you be able to use?: Trace tables, breakpoint debugging, print statements, and step-by-step code execution.
  • What is the difference between breakpoint debugging and print debugging?: A breakpoint pauses execution so state can be inspected interactively; print debugging records selected values or execution points in output.
  • What do read, write, and append modes do when opening a sequential text file?: Read accesses existing data; write creates/overwrites file content; append adds new content after the existing content.
  • At the B2 checkpoint, how do local and global variable scopes differ?: A local variable is limited to the block/function/method where it is defined; a global variable is accessible from a wider program scope.
  • Which five basic data types should still be secure at the B2 checkpoint?: Boolean value, char, decimal, integer, and string.
B2.1.3 + B2.1.4 · Learn

Core knowledge and application

4 / 11
B2.1.3Describe

How programs use common exception handling techniques

Programming fundamentals turn algorithms into reliable executable procedures. Scope, data types, debugging and exceptions all affect correctness.

Exam moveGive a detailed, accurate account of what happens or what something is like.
Required detail 1Potential points of failure in a program must include unexpected inputs, resource unavailability, logic errors
Required detail 2Role of exception handling in developing programs
Required detail 3Exception handling constructs that effectively manage errors must include try/catch in Java, and try/ except in Python, along with the finally block
Assessment boundaryPaper 2

Explain it without notes

Describe: How programs use common exception handling techniques in the context of a student-record processing program.

  • Potential points of failure in a program must include unexpected inputs, resource unavailability, logic errors
  • Role of exception handling in developing programs
  • Exception handling constructs that effectively manage errors must include try/catch in Java, and try/ except in Python, along with the finally block
B2.1.4Construct

And use common debugging techniques

Programming fundamentals turn algorithms into reliable executable procedures. Scope, data types, debugging and exceptions all affect correctness.

Exam moveProduce the required code, diagram, query, model or representation accurately.
Required detail 1Debugging techniques may include trace tables, breakpoint debugging, print statements and step-by- step code execution
Assessment boundaryPaper 2

Explain it without notes

Construct: And use common debugging techniques in the context of a student-record processing program.

  • Debugging techniques may include trace tables, breakpoint debugging, print statements and step-by- step code execution
B2.5.1 · Learn

Core knowledge and application

5 / 11
B2.5.1Construct

Code to perform file-processing operations

File processing connects a program to persistent data and requires careful control of reading, writing and data validity.

Exam moveProduce the required code, diagram, query, model or representation accurately.
Required detail 1Programs that manipulate text files
Required detail 2Opening a sequential file in various modes (read, write, append)
Required detail 3How to read from and write to files, append data to an existing file, and close a file once operations are completed
Required detail 4Classes for Java users may include Scanner, FileWriter, BufferedReader
Required detail 5Functions for Python users may include open(), read(), readline(), write(), close()
Assessment boundaryPaper 2

Explain it without notes

Construct: Code to perform file-processing operations in the context of a program that reads and updates saved attendance records.

  • Programs that manipulate text files
  • Opening a sequential file in various modes (read, write, append)
  • How to read from and write to files, append data to an existing file, and close a file once operations are completed
  • Classes for Java users may include Scanner, FileWriter, BufferedReader
  • Functions for Python users may include open(), read(), readline(), write(), close()
Trace / construct

Programming checkpoint

6 / 11
try:
    with open("scores.txt", "r") as f:
        for line in f:
            print(int(line.strip()))
except (OSError, ValueError) as error:
    print("Data could not be processed")
Before you run itTrace the code by hand. Identify state changes, branch/loop behaviour, and the final result.

Modify it

Change one condition, input or operation so the program solves a slightly different problem. Predict the effect before editing.

Worked example · B2.1.3 / B2.1.4

Failures, exceptions and debugging

7 / 11

Potential failures

  • Unexpected input: text entered where an integer is required.
  • Resource unavailable: a file or network resource cannot be opened.
  • Logic error: the program runs but produces the wrong result.

Debugging toolkit

  • trace table for changing variable values;
  • breakpoint debugging to pause at a chosen line;
  • temporary print/log statements;
  • step-by-step execution to inspect state after each statement.
f = None
try:
    f = open("scores.txt", "r")
    value = int(f.readline())
except (OSError, ValueError) as error:
    print("Could not read a valid score")
finally:
    if f is not None:
        f.close()
Debugging challengeA loop should total five scores but stops after four. Which technique would you use first, and what state would you inspect?
Apply

Transfer to a new scenario

8 / 11
ScenarioA student-record processing program needs a design or technical decision related to today’s topic. Explain what matters and why.
  • Potential points of failure in a program must include unexpected inputs, resource unavailability, logic errors
  • Role of exception handling in developing programs
  • Debugging techniques may include trace tables, breakpoint debugging, print statements and step-by- step code execution
  • Programs that manipulate text files
  • Opening a sequential file in various modes (read, write, append)
Exam lens

Paper 2 practice

9 / 11
Build the response before checking notesUse precise terminology and match the required depth.
  1. Describe: How programs use common exception handling techniques in the context of a student-record processing program.
  2. Construct: And use common debugging techniques in the context of a student-record processing program.
  3. Construct: Code to perform file-processing operations in the context of a student-record processing program.
Self-checkAnswer the exact command term. For explain, include mechanism/reason; for compare, pair criteria; for discuss/evaluate/justify, build supported reasoning and a conclusion.
2027 Case Study

2027 Case Study Launch

10 / 11

This is the first formal case-study checkpoint. The scenario is a creative design company evaluating generative AI for image creation. HL preparation will build around diffusion models, GANs, hybrid models, training data, computational demands and ethical/legal trade-offs.

Four HL research directions

  1. Iterative diffusion/denoising and computational demand.
  2. Training-data intellectual property, bias and mitigation.
  3. Generator–discriminator balance in GAN training.
  4. How hybrid models combine strengths and offset limitations across diffusion, GANs, VAEs and flow-based models.

First research checkpoint

Start a research note on diffusion models: identify why iterative denoising is computationally demanding.

Challenge focus: Explain how iterative denoising creates images and evaluate the computational demands of the process.

Homework

Finish the learning cycle

11 / 11

IA — main task

Continue Criterion D development. Keep code readable, record meaningful implementation decisions, and maintain testing/evidence notes as you work.

Syllabus — short

Complete one targeted Paper 2/Paper 1 retrieval task from today’s lesson.