How is it possible to convert a F# failwith exception to Scala.
I have the following code:
let rec getAny text =
let FailureText = "Text."
if test then failwith FailureText
else text
Just throw an Exception like the following?
throw new IllegalArgumentException("Text.");
In F# it would throw an Microsoft.FSharp.Core.FailureException.
What would you throw in Scala? Just a normal java.lang.Exception or RuntimeException?
You may use
sys.error(failureText), it just throws aRuntimeException. Otherwise, throw is fine if you want to choose another exception, or if error does not convey the intent.You may also consider
assert,assumeorrequire(defined in Predef)And of course you may dispense with the
else, but this is a matter of taste.