Stage 1 · Lesson 7 of 9
Exceptions and Result
has exceptions, but no . The compiler never forces you to catch anything, so you decide where handling makes sense. try returns a value, so val n = try { s.toInt() } catch (e: NumberFormatException) { 0 } works.
Many functions have a safe version that returns null instead of throwing, such as toIntOrNull. runCatching wraps a call in a Result that you can inspect. Use require and check to fail fast on programmer mistakes. code, Kotlin's async code, has one special rule.
Common trapThe trap in coroutine code is catching every Exception, including with runCatching, because that also catches CancellationException and stops a cancelled coroutine from actually stopping.
A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- GuideFreeKotlin Documentation
JetBrains
Start with the Kotlin tour, then the null safety and coroutines basics pages
- CourseFreeAndroid Basics with Compose
Google · Beginner
The Kotlin pathways in Units 1 to 3 teach the language with practice sets