loicdescotte
5/16/2014 - 4:00 PM

Scala futures error handling

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