Skip to content

Instantly share code, notes, and snippets.

@loicdescotte
Last active August 29, 2015 14:01
Show Gist options
  • Save loicdescotte/11094a92f6b28bc89acb to your computer and use it in GitHub Desktop.
Save loicdescotte/11094a92f6b28bc89acb to your computer and use it in GitHub Desktop.
Scala futures error handling
val f: Future[Int] = Future {
if(math.random < 0.5) 1 else throw new Exception("Oh no")
} recover {
case ex:Exception => {
println(ex.getMessage)
-1
}
}
f map println
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment