Checked Exceptions vs Unchecked Exceptions

There are two types of exceptions:

  • Checked exceptions: the compiler forces you to catch them
  • Unchecked exceptions: you are free to catch them or not

Checked Exceptions

How does the compiler force you to handle checked exceptions?

Code Example

Because Kotlin has no checked exceptions, we will use Java to demonstrate the behavior. A function signature can indicate exceptions that it may throw:

Get hands-on with 1400+ tech skills courses.