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.
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());
}
Checked: IOException: disk full
Unchecked: ArithmeticException: bad math
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