本文最后更新于 2021-08-05 11:42:59
Exception
scala中所有的异常,可以处理,也可以不处理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| object Demo1 { def main(args: Array[String]): Unit = { try{ var a = 1/0 throw new FileNotFoundException("aaa") }catch { case e:ArithmeticException=>println("exception") case e1:FileNotFoundException=>println(e1.getMessage) }finally { println("释放资源") } } @throws(classOf[RuntimeException]) @throws(classOf[IndexOutOfBoundsException]) def fun: Unit ={ println("111111111") } }
|
22异常
https://jiajun.xyz/2020/11/18/scala/22异常/