Skip to content

Instantly share code, notes, and snippets.

@seanparsons
Created June 16, 2011 11:16
Show Gist options
  • Save seanparsons/1029056 to your computer and use it in GitHub Desktop.
Save seanparsons/1029056 to your computer and use it in GitHub Desktop.
Weekly Scala Tip: As indiciated by @mariofusco here: http://twitter.com/mariofusco/status/81308217346506752 we should eliminate throwing exceptions up as much as possible.
scala> import scala.util.control._
import scala.util.control._
scala> Exception.catching(classOf[Throwable]).either{"1".toInt}
res2: Either[Throwable,Int] = Right(1)
scala> Exception.catching(classOf[Throwable]).either{"dave".toInt}
res3: Either[Throwable,Int] = Left(java.lang.NumberFormatException: For input string: "dave")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment