Scala error function is deprecated. Which alternative?

I am porting some Haskell code to Scala. In Haskell, I can use the error function. It seems at some point you can do it in Scala, but the ID environment shows me that it 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 am I using instead of the error function in Scala?

+4
source share
1 answer

You should use sys.erroras mentioned in the message deprecated.

@deprecated("Use `sys.error(message)` instead", "2.9.0")

You can run scala with a parameter -deprecationto get this message:

scala> def t = error("t")
<console>:7: warning: method error in object Predef is deprecated: Use `sys.error(message)` instead
+14
source

Source: https://habr.com/ru/post/1527778/


All Articles