aımnova
DashboardMy LearningCrash CoursesStudy Plan

Aimnova site navigation

Stay in the loop

Get the latest study resources and updates

New features, study tips and exam insights — straight to your inbox.

IB Diploma

  • IB Past Papers
  • IB Study Notes
  • IB Question Bank
  • IB Mock Exams
  • IB Revision

IB Subjects

  • IB Math AA
  • IB Math AI
  • IB Economics
  • IB Business Management
  • IB Physics
  • IB Biology
  • View all IB subjects→

IB Past Papers

  • IB Math AA HL Past Papers
  • IB Math AA SL Past Papers
  • IB Math AI HL Past Papers
  • IB Math AI SL Past Papers
  • IB Economics HL Past Papers
  • IB Economics SL Past Papers
  • IB ESS Past Papers
  • View all past papers→

Study Resources

  • Study Notes
  • Question Bank
  • Mock Exams
  • Crash Courses
  • Flashcards
  • Revision Guide
  • Exam Skills
  • Command Terms
  • Grade Calculator
  • Exam Timetable 2026

Aimnova

  • Features
  • Pricing
  • For Teachers
  • For Schools
  • For Parents
  • About Us
  • Blog
  • Contact
aımnova

IB study, practice and feedback built around the real exam.

TermsPrivacyCookies·© 2026 Aimnova. All rights reserved.c1e448f

Aimnova is not affiliated with or endorsed by the International Baccalaureate Organization (IB).

NotesComputer Science HLTopic 6.1Exception handling
Back to Computer Science HL Topics
6.1.35 min read

Exception handling (Computer Science HL)

IB Computer Science · Unit 6

Exam preparation

Practice the questions examiners actually ask

Our question bank mirrors real IB exam papers. Practice under timed conditions and track your progress across topics.

Start Practicing

Contents

  1. 1When something goes wrong at run time
  2. 2try, except and finally
  3. 3Handling, or preventing
  4. 4Exam-style question
The big idea: An exception is a problem that appears while the program is running — not a mistake in the code's grammar.

Without handling, the program simply stops. With handling, it can say what went wrong and carry on.

Unexpected input

  • Letters typed where a number was wanted
  • An empty answer, or a date that does not exist
  • The commonest source, because people are the source

Resource unavailable

  • A file that is missing, or locked by something else
  • A network or database that does not respond
  • Nothing is wrong with your code — the world changed

Logic errors

  • Dividing by a value that turned out to be zero
  • Reading past the end of a list
  • The code ran, but on values nobody planned for

Free preview

This is the free notes preview

You're reading the free notes. Aimnova Pro unlocks the full study experience — and you can try it with your first topic free to keep:

  • FlashcardsLock in vocabulary and key terms with spaced repetition.
  • Practice questionsAnswer exam-style questions and get instant AI marking.
  • Mock exams & past-paper vaultSit full mocks and see exactly how examiners award marks.
  • Personalised study planA daily plan built around your exam date and weak areas.
Start Studying Free Full access to Aimnova Pro · cancel anytime
try:
    age = int(input("Age: "))      # may fail if they type "abc"
    print(100 / age)               # may fail if they type 0
except ValueError:
    print("Please enter a whole number.")
except ZeroDivisionError:
    print("Age cannot be zero.")
finally:
    print("Done.")                 # runs either way
try {
    int age = Integer.parseInt(scanner.nextLine());  // may fail on "abc"
    System.out.println(100 / age);                   // may fail on 0
} catch (NumberFormatException e) {
    System.out.println("Please enter a whole number.");
} catch (ArithmeticException e) {
    System.out.println("Age cannot be zero.");
} finally {
    System.out.println("Done.");                     // runs either way
}
1

try — the risky part

Put only the lines that might fail inside it.

A try block wrapped round the whole program hides where the problem actually was, which makes it far harder to fix.

2

except — what to do about it

Runs only when the matching kind of problem occurs.

Having one except per kind lets you give a message that actually helps: "enter a whole number" is useful; "an error occurred" is not.

3

finally — always, either way

Runs whether or not anything failed.

This is where you close a file or release a connection — so it happens even when the code in try stopped halfway through.

4

Java says catch

Java writes try / catch / finally where Python writes try / except / finally.

The structure and the reasoning are identical; only the keyword differs.

Never catch everything and say nothing: A bare except that silently ignores the problem is worse than no handling at all.

The program appears to work while producing wrong results, and the cause is now invisible.

Practice with exam-style questions

Answer exam-style questions and get AI feedback that shows you exactly what examiners want to see in a full-marks response.

Try Practice FreeYour first topic is free to keep • No credit card required

Validate first

  • Check before acting — is the list empty? is the divisor zero?
  • Right when you can reasonably predict the problem
  • Reads clearly, and costs nothing when all is well
  • Cannot cover everything: a file can vanish between the check and the read

Handle the exception

  • Let it happen, and deal with it when it does
  • Right when the problem is outside your control
  • The only option for files, networks and databases
  • Needs a specific message, or it tells the user nothing
Real programs do both: Validate the things you can predict — an empty field, a number out of range.

Handle the things you cannot — a missing file, a network that stops answering. Neither one alone is enough.
Why it matters beyond tidiness: A crash loses whatever the user was doing, and an unhandled error message can reveal file paths and internal details that help an attacker.

Handling exceptions is partly a security measure.

How this is tested — you must name the failure, the construct that catches it, and what the user is told. It comes up two ways:

Paper 2 — working with code

  • Describe exception handling, 3-5 marks
  • Add handling to a given fragment
  • Name the points of failure in a program

Paper 2 — the algorithmic-thinking question

  • Identify what could fail, with no code shown
  • Say what the program should do about it
The classic trap: Wrapping everything in one try and printing "an error occurred". Marks come from specific handling: which failure, which except, and a message the user can act on.
IB-style questionDescribe[5 marks]

A program reads a class list from a file and calculates the average mark. Describe the points of failure and how each should be handled.

Model answer plan

See the answer broken into clear points, with guidance on how each point earns marks.

Claim your free topic

Try an IB Exam Question — Free AI Feedback

Test yourself on Exception handling. Write your answer and get instant AI feedback — just like a real IB examiner.

the term exception. [1 mark]

Related Computer Science HL Topics

Continue learning with these related topics from the same unit:

6.1.1Variables and data types6.1.2Substrings6.1.4Debugging6.2.1Static vs dynamic structures
View all Computer Science HL topics
Improve your exam techniqueCommand terms, paper structure, and mark-scheme tips for Computer Science HL
Previous6.1.2SubstringsNextDebugging6.1.4

21 questions to test your understanding

Reading is just the start. Students who tested themselves scored 82% on average — try IB-style questions with AI feedback.

Start FreeView All Computer Science HL Topics