I like Scala’s sys.error function – but I want to distinguish two cases: internal errors (e.g. database problem) and user errors (invalid input).
I tried extending Scala – but it doesn’t seem to work:
package scala
class UserException(msg: String) extends RuntimeException(msg)
package object err {
def internal(message: String): Nothing =
sys.error(message)
def usr(message: String): Nothing =
throw new UserException(message)
}
How should I define err.usr() to be able to use it without an explicit import?
You can’t, only
scala.Predefis imported by default and it’s not user extensible in any useful way.