Skip to content

Instantly share code, notes, and snippets.

@rail-rate
Created August 16, 2019 15:12
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 rail-rate/f0b2b499a1f58b1fefde939a63cebbc4 to your computer and use it in GitHub Desktop.
Save rail-rate/f0b2b499a1f58b1fefde939a63cebbc4 to your computer and use it in GitHub Desktop.
try-catch7
fun main(args: Array<String>) {
val text = "abcde"
sub1(text)
}
fun sub1(a : String){
try{
sub2(a)
}catch(e : NumberFormatException){ //sub2から投げられた例外をここでキャッチ
println("sub1で処理") //表示されている
}
}
fun sub2(a : String){
try{
val number = a.toInt()
println("number = ${number}")
}catch(e : NumberFormatException){
throw e //例外がここからsub1に移動
println("sub2") //移動したのでこれは表示されていない
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment