Back to the 2026 paper

Module 4: Exception Handling

20267m

Compare checked and unchecked exceptions using suitable examples. Analyse how the compiler treats each category and discuss appropriate handling strategies.

Worked SolutionAI Assisted

Checked vs unchecked exceptions

Checked Unchecked
Compiler requires catching or declaring them No compile-time catch/declare requirement
Subclasses of Exception excluding RuntimeException RuntimeException and its subclasses
Example: IOException, SQLException Example: NullPointerException, ArithmeticException
import java.io.IOException;
class Example {
    static void read() throws IOException {
        throw new IOException("Read failed");
    }
    public static void main(String[] args) {
        try { read(); }
        catch (IOException e) { System.err.println(e.getMessage()); }
    }
}

Catch exceptions when recovery is possible, or declare checked exceptions with throws. Prevent unchecked exceptions through validation and correct program logic; do not catch Exception indiscriminately.

Similar questions

Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.