什么是 Scala 标准异常?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7744690/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 03:34:01  来源:igfitidea点击:

What are Scala standard exceptions?

exceptionscalanotimplementedexception

提问by Ivan

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

Scala 中常见的标准异常是什么?我对 .Net 的NotImplementedException等价物如何称呼特别感兴趣?

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

更新:关于org.apache.commons.lang.NotImplementedException的答案NotImplementedException似乎是

采纳答案by Daniel C. Sobral

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?

其余的来自 Java,它几乎涵盖了所有方面。它回避了这些 Scala 方法在其他平台上抛出什么的问题,不是吗?

回答by axel22

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

NotImplementedException目前正在考虑斯卡拉2.10,大概。看到这个线程

回答by Kim Stebel

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

您可以使用 Java 中已经存在的任何默认值。Scala 并未真正向 Java 中的标准异常添加任何内容。