Scala: Try and casing on Success and Failure - Stack Overflow
stackoverflow.com › questions › 20170946Nov 24, 2013 · I've implemented the following code to handle the completion of my future, and it compiles fine. resultFuture.onComplete ( { case Success => // success logic case Failure => // failure logic }) I'm a little confused as to how it works, I'm presuming it does as I copied it from a similar example from the Scala documentation. I understand that onComplete requires a function that takes a Try as input, and that Success and Failure are case classes that extend from Try.
A simple Scala Try, Success, Failure example (reading a file)
alvinalexander.com › scala › try-success-failureSep 29, 2022 · A simple Scala Try, Success, Failure example (reading a file) By Alvin Alexander. Last updated: September 29, 2022. Sorry, I don’t have much free time these days, so without any discussion, here’s a simple Scala Try, Success, and Failure example: import scala.io.Source import scala.util. {Try,Success,Failure} object Test extends App { def readTextFile (filename: String): Try [List [String]] = { Try (Source.fromFile (filename).getLines.toList) } val filename = "/etc/passwd" readTextFile ...