Exceptions: catching a supertype also catches its checked and unchecked subtypes

A catch clause for a broad type such as Exception matches any more specific exception thrown inside the try block, whether that subtype is checked like IOException or unchecked like ArrayStoreException.

Code
for (boolean throwChecked : new boolean[]{true, false}) {
    try {
        if (throwChecked) {
            throw new java.io.IOException("checked failure");
        }
        Object[] numbers = new Integer[2];
        numbers[0] = "not an integer";
    } catch (Exception e) {
        System.out.println("Caught as Exception: " + e.getClass().getSimpleName() + ": " + e.getMessage());
    }
}
Output
Caught as Exception: IOException: checked failure
Caught as Exception: ArrayStoreException: java.lang.String
Advertisement
More in JAVA

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-09-27

© Java Coding Hub · About · Contact · Privacy · Terms