Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- scala> import scala.util.control.Exception.allCatch
- import scala.util.control.Exception.allCatch
- scala> def intValueOf(s: String): Option[Int] = allCatch.opt { s.toInt }
- intValueOf: (s: String)Option[Int]
- scala> val x = intValueOf("hello")
- x: Option[Int] = None
- scala> val y = intValueOf("12345")
- y: Option[Int] = Some(12345)
Add Comment
Please, Sign In to add comment