import java.io.IOException
/**
* 异常捕获与处理
*/
object excepitonUse {
def main(args: Array[String]): Unit = {
try {
throw new IOException("throw a user define exception!!!")
} catch {
case e1: IOException => printf("found io exception...")
case e2: IllegalArgumentException => {
printf("do something when illegal happened.")
}
} finally {
printf("finally ......")
}
}
}
原文:https://www.cnblogs.com/yxj0728/p/9281777.html