kotlin
Kotlin Exceptions
Exception and error types thrown by the Kotlin runtime and standard library, including Kotlin-specific exceptions, coroutine cancellation signals, and common collection errors.
15 codes
· All codes 15 codes
- ArithmeticException ArithmeticException Thrown when an exceptional arithmetic condition occurs, most commonly integer division by zero.
- CancellationException CancellationException Thrown when a coroutine is cancelled. This exception is treated specially by the coroutines library: it does not propagate to parent coroutines and is silently swallowed by most coroutine builders. Catching it without rethrowing will suppress cancellation.
- ClassCastException ClassCastException Thrown at the JVM level when an object is cast to an incompatible type. In idiomatic Kotlin this is usually surfaced as a TypeCastException, but it can originate from Java interop or reflection.
- ConcurrentModificationException ConcurrentModificationException Thrown by a collection iterator when the underlying collection is modified while iterating over it, which would produce undefined iteration behavior.
- IllegalArgumentException IllegalArgumentException Thrown when a function receives an argument that violates its contract. Also thrown by the require() and requireNotNull() standard library functions.
- IllegalStateException IllegalStateException Thrown to signal that a method was called when the object is in an inappropriate state for that operation. Also thrown by the check() and checkNotNull() standard library functions.
- IndexOutOfBoundsException IndexOutOfBoundsException Thrown when an index used to access a list, array, or other indexed collection is negative or greater than or equal to the collection's size.
- KotlinNullPointerException KotlinNullPointerException Thrown when the not-null assertion operator (!!) is applied to a null value, or when a platform type value assumed to be non-null turns out to be null at runtime.
- NoSuchElementException NoSuchElementException Thrown when a collection or iterator is accessed for an element that does not exist, such as calling first() or last() on an empty list, or next() on an exhausted iterator.
- NotImplementedError NotImplementedError Thrown by the TODO() function or when an abstract member is called without a concrete implementation. Signals that the code is intentionally incomplete.
- OutOfMemoryError OutOfMemoryError Thrown by the JVM when the heap cannot satisfy an allocation request. Often indicates a memory leak or an unexpectedly large data structure.
- StackOverflowError StackOverflowError Thrown when the call stack overflows, most often due to unbounded or mutually recursive function calls with no base case.
- TimeoutCancellationException TimeoutCancellationException A subclass of CancellationException thrown by withTimeout when the time limit elapses before the block completes. The enclosing coroutine scope is cancelled; use withTimeoutOrNull to return null instead.
- TypeCastException TypeCastException Thrown when an unsafe type cast using the as operator fails because the object is not an instance of the target type. Use as? to return null instead of throwing.
- UninitializedPropertyAccessException UninitializedPropertyAccessException Thrown when a lateinit var property is read before it has been assigned a value.