O'Reilly logo

Kotlin Programming: The Big Nerd Ranch Guide, First Edition by David Greenhalgh, Josh Skeen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required