Skip to content

Instantly share code, notes, and snippets.

@renaudcerrato
Created February 24, 2019 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renaudcerrato/8db2a8895adaa45ca6587a5447e51f4f to your computer and use it in GitHub Desktop.
Save renaudcerrato/8db2a8895adaa45ca6587a5447e51f4f to your computer and use it in GitHub Desktop.
Kotlin Try/Catch expression
// the returned value is the last expression of the try or catch block
val a: Int? = try { parseInt(input) } catch (e: NumberFormatException) { null }
fun printNumber(reader: BufferedReader) {
val number = try {
parseInt(reader.readLine())
} catch (e: NumberFormatException) {
return
}
println(number)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment