7 Null Safety and Exceptions
Some elements in Kotlin can be assigned a value of null. Null is a special value; in fact, it indicates that the value of an element does not exist. In many programming languages, null is a common cause of crashes and errors, because a nonexistent value cannot be asked to do anything. Kotlin has several language features that force programmers to be mindful of null values in their programs, which helps avoid those crashes.
In this chapter, you will learn why null causes a crash, how Kotlin protects against null by default at compile time, and how to safely work with values that could be null when you need them. You will also see how to work with exceptions in Kotlin: indicators that something went wrong ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access