try-cacth-finally ArrayIndexOutOfBoundsException,program go on,kotlin
fun sub(size: Int): List<Int> {
val l = listOf(1, 2, 3)
var list = l.subList(0, size)
return list
}
fun okgo(): List<Int> {
var list = emptyList<Int>()
try {
list = sub(999)
} catch (e: Exception) {
e.printStackTrace()
} finally {
return list
}
}
fun main(args: Array<String>) {
val list = okgo()
//即便kotlin发生数组越界,异常捕获后,后面代码继续执行
println("go")
println("${list.size}")
}
文章来源地址https://www.toymoban.com/news/detail-513095.html
文章来源:https://www.toymoban.com/news/detail-513095.html
java.lang.IndexOutOfBoundsException: toIndex = 999
at java.base/java.util.AbstractList.subListRangeCheck(AbstractList.java:509)
at java.base/java.util.AbstractList.subList(AbstractList.java:499)
at MainKt.sub(Main.kt:3)
at MainKt.okgo(Main.kt:10)
at MainKt.main(Main.kt:19)
go
0
到了这里,关于try-cacth-finally ArrayIndexOutOfBoundsException,program go on,kotlin的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!