No checked exceptions
Kotlin only knows runtime exceptions, a throws
declaration is neither necessary nor possible.
Of course try
/catch
/finally
blocks are available - just never required.
While Java differentiates between runtime exceptions and checked exceptions, in Kotlin there are only the former.
Checked exceptions
The difference to runtime exceptions is that any function that can potentially raise a checked exception must declare it with throws
.
In addition, the client is forced to encapsulate the call in a try/catch
block or to declare the exception’s passing on with throws
.
This is not necessary for runtime exceptions.
Therefore, in Kotlin the declaration of possibly raised exceptions with throws
is not necessary (and not even possible - the corresponding keyword is just missing).
Nevertheless, one can use try/catch
- just like in Java - to handle possible exceptions.