Exceptions: a checked exception must be declared with throws, an unchecked one need not

The compiler forces a method that can throw a checked exception to either catch it or declare it with throws; a RuntimeException such as ArithmeticException needs no such declaration because it is unchecked.

Code
static void mustDeclare() throws java.io.IOException {
    throw new java.io.IOException("disk full");
}
static void noDeclarationNeeded() {
    throw new ArithmeticException("bad math");
}
try {
    mustDeclare();
} catch (java.io.IOException e) {
    System.out.println("Checked: " + e.getClass().getSimpleName() + ": " + e.getMessage());
}
try {
    noDeclarationNeeded();
} catch (ArithmeticException e) {
    System.out.println("Unchecked: " + e.getClass().getSimpleName() + ": " + e.getMessage());
}
Output
Checked: IOException: disk full
Unchecked: ArithmeticException: bad math
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