Last active
April 26, 2016 21:38
-
-
Save johntbush/eed56819180de112cbca107d00e5b3e5 to your computer and use it in GitHub Desktop.
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
import scala.concurrent.Future | |
import scala.util.{Failure, Success, Try} | |
import scala.concurrent.ExecutionContext.Implicits.global | |
def fail = throw new RuntimeException("error now") | |
def failInFuture() = Future { throw new RuntimeException("error in future") } | |
try { | |
fail | |
} catch { | |
case e: Exception => println(e.getMessage) | |
} | |
failInFuture().onComplete { | |
case Success(result) => | |
case Failure(t) => println("error reported in onComplete") | |
} | |
failInFuture().onFailure { | |
case e => println("error reported in onFailure") | |
} | |
failInFuture().recover { | |
case e => println("error reported in recover") | |
} | |
Try (fail).failed.map(e => println(e.getMessage)) | |
failInFuture().failed.map(e => println(e.getMessage)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment