首页 > 代码库 > scala 异常

scala 异常

异常捕捉

 

scala> val a  = Seq(1,2,3,6,4)
a: Seq[Int] = List(1, 2, 3, 6, 4)

scala>     val b = a.map(f=>{
     |       try{
     |         Some(f/(f-1))
     |       }catch{
     |         case e:Exception=>None
     |       }
     |     }).foreach(println)
None
Some(2)
Some(1)
Some(1)
Some(1)
b: Unit = ()

 

scala 异常