Scala Catch Last Error

[Solved] Scala Catch Last Error | Solidity - Code Explorer | yomemimo.com
Question : scala catch last error

Answered by : xenophobic-xenomorph-tyzvetbbcynk

import scala.io.StdIn
import scala.util.{Try, Success, Failure}
def divide: Try[Int] = { val dividend = Try(StdIn.readLine("Enter an Int that you'd like to divide:\n").toInt) val divisor = Try(StdIn.readLine("Enter an Int that you'd like to divide by:\n").toInt) val problem = dividend.flatMap(x => divisor.map(y => x/y)) problem match { case Success(v) => println("Result of " + dividend.get + "/"+ divisor.get +" is: " + v) Success(v) case Failure(e) => println("You must've divided by zero or entered something that's not an Int. Try again!") println("Info from the exception: " + e.getMessage) divide }
}

Source : https://www.scala-lang.org/api/2.13.6/scala/util/Try.htmlimport scala.io.StdIn import scala.util.{Try, Success, Failure} def divide: Try[Int] = { val dividend = Try(StdIn.readLine("Enter an Int that you'd like to divide:\n").toInt) val divisor = Try(StdIn.readLine("Enter an Int that you'd like to divide by:\n").toInt) val problem = dividend.flatMap(x => divisor.map(y => x/y)) problem match { case Success(v) => println("Result of " + dividend.get + "/"+ divisor.get +" is: " + v) Success(v) case Failure(e) => println("You must've divided by zero or entered something that's not an Int. Try again!") println("Info from the exception: " + e.getMessage) divide } } | Last Update : Tue, 20 Sep 22

Question : scala catch last error

Answered by : xenophobic-xenomorph-tyzvetbbcynk

try { // your scala code here
}
catch { case foo: FooException => handleFooException(foo) case bar: BarException => handleBarException(bar) case _: Throwable => println("Got some other kind of Throwable exception")
} finally { // your scala code here, such as closing a database connection // or file handle
}

Source : https://docs.scala-lang.org/overviews/scala-book/try-catch-finally.htmltry { // your scala code here } catch { case foo: FooException => handleFooException(foo) case bar: BarException => handleBarException(bar) case _: Throwable => println("Got some other kind of Throwable exception") } finally { // your scala code here, such as closing a database connection // or file handle } | Last Update : Tue, 20 Sep 22

Answers related to scala catch last error

Code Explorer Popular Question For Solidity