Created
November 1, 2014 18:33
-
-
Save ayoub-benali/dabed51e64ca4b4ab160 to your computer and use it in GitHub Desktop.
Try's trap
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.util.Try | |
// isn't the following line supposed not to compile ? | |
val foo: Try[Unit] = Try{1+1}.map{x => Try{x/0}} | |
// foo: scala.util.Try[Unit] = Success(()) | |
val foo: Try[Unit] = Try{1+1}.flatMap{x => Try{x/0}} | |
// scala.util.Try[Unit] = Failure(java.lang.ArithmeticException: / by zero) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I got your point, it guess it is because there is an implicit conversion by the compiler from any type to Unit ?
it is funny that the error is caught by the compiler in this case: