import java.io.{FileNotFoundException, FileReader, IOException}
/**
* Created by vincentliu on 7/18/2017.
*/
object ex {
def main(args: Array[String]): Unit = {
try{
val f = new FileReader("input.txt")
} catch{
case ex: FileNotFoundException => {
println("Missing file exception")
}
case ex: IOException => {
println("IO Exception")
}
} finally {
println("exit....")
}
}
}
Scala——异常
最新推荐文章于 2024-05-02 12:44:48 发布
本文通过一个Scala程序示例展示了如何处理文件读取过程中可能出现的FileNotFoundException和IOException。程序使用了try-catch-finally结构来确保即使发生异常也能正常退出。
580

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



