A functional interface's abstract method fixes which checked exceptions an implementing lambda may throw; when it declares none, the lambda body must catch any checked exception itself rather than let it escape.
Runnable task = () -> {
try {
throw new java.io.IOException("simulated read failure");
} catch (java.io.IOException e) {
System.out.println("Caught inside lambda: " + e.getClass().getSimpleName() + ": " + e.getMessage());
}
};
task.run();
System.out.println("Runnable completed normally");
Caught inside lambda: IOException: simulated read failure
Runnable completed normally
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