Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/chen18677338530/article/details/91451044
Scala abnormal Introduction
object FunDemo8 {
def main(args: Array[String]): Unit = {
try {
val r = 10 / 0
} catch {
case ex: ArithmeticException => {
println(ex)
}
case ex: Exception => {
println("捕获异常")
}
} finally {
println("最后执行的代码")
}
println("--------")
}
}
Failure Notes
object FunDemo9 {
def main(args: Array[String]): Unit = {
def test():Nothing = {
throw new ArithmeticException()
}
test()
}
}
object FunDemo10 {
def main(args: Array[String]): Unit = {
f1()
}
@throws(classOf[NumberFormatException])
def f1() = {
"abc".toInt
}
}