Scala基础篇-04 try表达式
1.try表达式
- 定义
try{}
catch{}
finally{}
//例子
try{
Integer.parseInt("dog")
}catch {
case _ => 0
}finally {
println("always be printed")
}
2.match表达式
exp match{ case p1 =>val1 case p2 =>val2 ... case _ => valm } val code=1 code match{ case 1 =>"one" case 2 =>"two" case _ =>"other" }
posted on 2018-10-29 09:45 moonlight.ml 阅读(573) 评论(0) 编辑 收藏 举报