Exceptions & Result

throw, try as an expression, custom exceptions, runCatching and Result.

Kotlin uses exceptions like Java, with two differences: there are no checked exceptions (you are not forced to declare or catch them), and try is an expression. runCatching turns code that throws into a Result value that can be inspected.

Parsing with exceptions

?: throw ... turns a missing value into an exception in one line.

val text = try { ... } catch { ... } uses try as an expression.

runCatching { } returns Result: getOrNull, getOrDefault, isFailure.

error("...") throws IllegalStateException; finally always runs.

catch (e: Exception) { } // swallow everything Catch the specific exception you can handle, and log or rethrow the rest

Catching every exception silently hides real bugs (and in coroutines, can swallow cancellation).

Does Kotlin have checked exceptions?

No. Kotlin does not force callers to catch or declare exceptions; use @Throws when Java callers need the information.