Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.util.control.Exception._
- import java.net._
- val s = "http://www.scala-lang.org/"
- val x1 = catching(classOf[MalformedURLException]) opt new URL(s)
- val x2 = catching(classOf[MalformedURLException], classOf[NullPointerException]) either new URL(s)
- /** Apply this catch logic to the supplied body, mapping the result
- * into `Option[T]` - `None` if any exception was caught, `Some(T)` otherwise.
- */
- def opt[U >: T](body: => U): Option[U] = toOption(Some(body))
- val s = "http://www.scala-lang.org/"
- val x1 = catching(classOf[MalformedURLException]).opt(new URL(s))
- val x2 = catching(classOf[MalformedURLException], classOf[NullPointerException]).either(new URL(s))
Add Comment
Please, Sign In to add comment