Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are Scala standard exceptions?

What are the common standard exceptions in Scala? I am especially interested in how is .Net's NotImplementedException equivalent called?

UPDATE: The answer about the NotImplementedException seems to be org.apache.commons.lang.NotImplementedException

like image 433
Ivan Avatar asked Oct 12 '11 18:10

Ivan


People also ask

What are exceptions in Scala?

An exception is an event that changes the normal flow of a program. Exception handling is the mechanism to respond to the occurrence of an exception. Exceptions can be checked or unchecked. Scala only allows unchecked exceptions, though.

How do you declare exceptions in Scala?

Exception handling is the mechanism to respond to and investigate the occurrence and cause of an exception. It is best practice in Scala to handle exceptions using a try{...} catch{...} block, similar to how it is used in Java, except that the catch block uses pattern matching to identify and handle exceptions.

Why does Scala have no checked exceptions?

However, unlike Java, Scala has no “checked” exceptions—you never have to declare that a function or method might throw an exception. In Java, “checked” exceptions are checked at compile time. If your method might throw an IOException, you must declare it.

What are the different types of exceptions in Java?

There are mainly two types of exceptions in Java as follows: Checked exception. Unchecked exception.


3 Answers

Almost nothing:

package scala {
  final class MatchError(obj: Any) extends RuntimeException
  final class UninitializedError extends RuntimeException("uninitialized value")
  final case class UninitializedFieldError (msg: String) extends RuntimeException(msg)

  package util.regex {
    class SyntaxError(e: String) extends RuntimeException(e)
  }

  package xml {

    class BrokenException() extends java.lang.Exception
    case class MalformedAttributeException(msg: String) extends RuntimeException(msg)

    package dtd {
      case class ValidationException(e: String) extends Exception(e)
    }

    package include {
      class CircularIncludeException(message: String) extends XIncludeException
      class UnavailableResourceException(message: String) extends XIncludeException(message)
      class XIncludeException(message: String) extends Exception(message)
    }

    package parsing {
      case class FatalError(msg: String) extends java.lang.RuntimeException(msg)
    }
  }
}

The rest comes from Java, which cover pretty much all corners. It begs the question of what these Scala methods throw on other platforms, doesn't it?

like image 92
Daniel C. Sobral Avatar answered Oct 22 '22 12:10

Daniel C. Sobral


The NotImplementedException is currently being considered for Scala 2.10, probably. See this thread.

like image 21
axel22 Avatar answered Oct 22 '22 13:10

axel22


You can just use whatever default already exists in Java. Scala doesn't really add anything to the standard exceptions in Java.

like image 2
Kim Stebel Avatar answered Oct 22 '22 12:10

Kim Stebel