Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala error function deprecated. What is the alternative?

Tags:

haskell

scala

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?

like image 517
M.K. Avatar asked Feb 19 '14 19:02

M.K.


1 Answers

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
like image 52
senia Avatar answered Sep 30 '22 18:09

senia