22异常

本文最后更新于 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异常/
作者
Lambda
发布于
2020年11月18日
更新于
2021年8月5日
许可协议