object 异常处理 {
def main(args: Array[String]): Unit = {
// 1.捕获
try {
10 / 0
} catch {
// case e: ArithmeticException => println("算数异常")
// case e: NullPointerException => println("空指针异常")
case e: Exception => e.printStackTrace()
} finally {
println("释放资源的代码")
}
println("看看我会不会执行123")
// 2.抛出
throw new Exception("将异常抛给调用者处理")
println("看看我会不会执行456")
}
}