I am porting some Haskell code over into Scala. In Haskell I can use the error function. It seems at some point you could do this in Scala but the IDE is showing me that this is deprecated now. Here is the code:
def prime (n : Int) : Boolean = () match {
case _ if n < 1 => error("not a positive integer")
case _ if n == 1 => false
case _ => ld (n) == n
}
What do I use instead of the error function in Scala now?
You should use sys.error
as mentioned in deprecated
message.
@deprecated("Use `sys.error(message)` instead", "2.9.0")
You could run scala with -deprecation
option to get this message:
scala> def t = error("t")
<console>:7: warning: method error in object Predef is deprecated: Use `sys.error(message)` instead
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With