Guest User

Untitled

a guest
Jan 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import scala.util.control.Exception._
  2. import java.net._
  3.  
  4. val s = "http://www.scala-lang.org/"
  5. val x1 = catching(classOf[MalformedURLException]) opt new URL(s)
  6. val x2 = catching(classOf[MalformedURLException], classOf[NullPointerException]) either new URL(s)
  7.  
  8. /** Apply this catch logic to the supplied body, mapping the result
  9. * into `Option[T]` - `None` if any exception was caught, `Some(T)` otherwise.
  10. */
  11. def opt[U >: T](body: => U): Option[U] = toOption(Some(body))
  12.  
  13. val s = "http://www.scala-lang.org/"
  14. val x1 = catching(classOf[MalformedURLException]).opt(new URL(s))
  15. val x2 = catching(classOf[MalformedURLException], classOf[NullPointerException]).either(new URL(s))
Add Comment
Please, Sign In to add comment