The following REPL snippets presume:
import scala.util.{Try, Success, Failure}
Why do these two statements not pass compilation? I get "constructor cannot be instantiated to expected type":
Failure(new Exception("a")) match {
case Success(i) => "a"; case Failure(e) => "b"; case _ => "c"; }
Success(123) match {
case Success(i) => "a"; case Failure(e) => "b"; case _ => "c"; }
I can get the success value out of a Try with get or toOption. Is there a corresponding way to get the failing Throwable value or Option[Throwable]?
EDIT: Casting from Failure/Success to Try works
Failure(new Exception("a")).asInstanceOf[Try[Int]] match {
case Success(i) => "a"; case Failure(e) => "b"; case _ => "c"; }
Success(123).asInstanceOf[Try[Int]] match {
case Success(i) => "a"; case Failure(e) => "b"; case _ => "c"; }