目录
摘要
try…catch
异常
- Scala 没有检查异常
throw表达式的类型是Nothing
try {
throw new IOException()
} catch {
//not care exception
case _: IOException => println("io exception")
//care exception
case e: Exception => e.printStackTrace();
} finally {
}
以上,_ 用于不需要使用产生的异常对象时使用。
本文深入探讨了Scala语言中异常处理的机制,包括try...catch结构的使用方式、异常类型的定义及处理策略。文章通过示例代码展示了如何捕获并处理不同类型的异常,以及如何使用finally块确保代码的正确执行。
1839

被折叠的 条评论
为什么被折叠?



