Created
June 16, 2011 11:16
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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