Last active
August 29, 2015 14:01
-
-
Save loicdescotte/11094a92f6b28bc89acb to your computer and use it in GitHub Desktop.
Scala futures error handling
This file contains 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
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