try {var n = 10 / 0} catch {case ex: ArithmeticException => println("发生算数异常")case ex : NullPointerException => println("发生异常1")case ex: Exception => ex.printStackTrace()} finally {println("释放资源 ")}
- Scala没有编译时异常,异常都是在运行的时候捕获处理
throw 抛出异常对象,都是Throwable子类,throw表达式有类型,就是Nothing
def test(): Nothing = {throw new Exception("不对")//底下的代码不会执行}
Scala throws注解
