...

/

Checked Exceptions vs Unchecked Exceptions

Checked Exceptions vs Unchecked Exceptions

Learn the difference between checked and unchecked exceptions and understand their pros and cons

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:

Access this course and 1400+ top-rated courses and projects.