Created
February 24, 2019 08:56
-
-
Save renaudcerrato/8db2a8895adaa45ca6587a5447e51f4f to your computer and use it in GitHub Desktop.
Kotlin Try/Catch expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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