6 Null Safety and Exceptions
Null is a special value that indicates that the value of a var or val does not exist.
In many programming languages, including Java, null is a common cause of crashes, because a nonexistent value cannot be asked to do anything.
Kotlin requires a specific declaration if a var or val can accept null as a value, which helps avoid this type of crash.
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 nullable values in Kotlin when you require them. You will also see how to work with what are called exceptions in Kotlin, indicators that something went wrong in your program.
To see these issues in action, you ...
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