Exception Types and Their Hierarchy
Explore the different exception types in Kotlin including IllegalArgumentException and IllegalStateException. Understand how Kotlin's require, check, and error functions help manage exceptions. Gain insight into the exception hierarchy, distinguishing recoverable exceptions from unrecoverable errors, and learn best practices for handling exceptions in Kotlin programming.
We'll cover the following...
Exception types
A few types of exceptions are defined in Kotlin that we use in certain situations. Some of the most important ones are:
IllegalArgumentException: We use this when an argument has an incorrect value. For example, when we expect our argument value to be bigger than zero but it is not.IllegalStateException: We use this when the state of our system is incorrect. This means the values of properties are not accepted by a function call. ...