Created
August 16, 2019 14:21
-
-
Save rail-rate/368f2475d695a9a69e0bab8865c0159b to your computer and use it in GitHub Desktop.
try-catch5
This file contains 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
fun main(args: Array<String>) { | |
val text = "abcde" | |
try{ | |
val number = text.toInt() | |
println("number = ${number}") | |
}catch(e : NumberFormatException){ | |
println("${text}は数字に変換出来ません") | |
}catch(e : ArrayIndexOutOfBoundsException){ | |
println("文字を入力してください") | |
}catch(e : Exception){ | |
println("何かのエラーが起きました") | |
}finally{ //catchの最後に入れる | |
prntln("スタートに戻ってください") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment