- Scala不支持java的“检查异常”,所有的异常都被当做“不受检查异常”(即 运行时异常)
- Scala的异常捕获通过try - catch 语句
import java.io.FileReader import java.io.FileNotFoundException import java.io.IOException try{ val f = new FileReader("./test.txt") } catch { case ex: FileNotFoundException => println("File not found") case ex: IOException => println("IOException") } finally { f.close() }
【不完善,待补充】