Skip to content
Commitwise
Menu

Checked exception

A Java exception the compiler forces you to either catch or declare in the method signature.

Definition

In Java, exceptions that extend Exception but not RuntimeException are checked: a method that can throw one must say so with throws, and every caller must catch it or declare it too. They make failures visible in signatures, but they don't work well with lambdas and can leak implementation details. Kotlin has no checked exceptions, and Swift marks failure with throws and try instead.

In practice

Files.readString(path) throws IOException, so code calling it must handle or declare IOException.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.