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 ...
Get Kotlin Programming: The Big Nerd Ranch Guide, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.