Exceptions
Like many other languages, Kotlin also includes exceptions to indicate that something went wrong in your program. This is important, because the world of NyetHack is a place in which things can indeed go wrong.
Let’s see some examples. Start by creating a new file in NyetHack called SwordJuggler.kt and adding a main function.
Against your better judgment, a group of tavern attendees has convinced you to juggle some swords. You will keep track of the number of swords that you are juggling with a nullable integer. Why a nullable integer? If swordsJuggling is null, then you lack proficiency in sword juggling and your journey in NyetHack may be cut short.
Begin by adding variables for the number of swords you are juggling ...
Get Kotlin Programming: The Big Nerd Ranch Guide, First 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.