对于不支持/实现的操作,在 Java 中抛出的标准异常是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/829136/
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-08-11 19:57:39  来源:igfitidea点击:

What is the standard exception to throw in Java for not supported/implemented operations?

java

提问by Krishna Kumar

In particular, is there a standard Exceptionsubclass used in these circumstances?

特别是,是否有Exception在这些情况下使用的标准子类?

采纳答案by dfa

java.lang.UnsupportedOperationException

java.lang.UnsupportedOperationException

Thrown to indicate that the requested operation is not supported.

抛出以指示不支持请求的操作。

回答by Guillaume

If you want more granularity and better decription, you could use NotImplementedException from commons-lang

如果你想要更多的粒度和更好的描述,你可以使用commons-lang 中的NotImplementedException

Warning: Available before versions 2.6 and after versions 3.2, only.

警告:仅在 2.6 版之前和 3.2 版之后可用。

回答by steffen

Differentiate between the two cases you named:

区分您命名的两种情况:

回答by Benny Neugebauer

If you create a new (not yet implemented) function in NetBeans, then it generates a method body with the following statement:

如果您在NetBeans 中创建一个新的(尚未实现的)函数,那么它会生成一个包含以下语句的方法体:

throw new java.lang.UnsupportedOperationException("Not supported yet.");

Therefore, I recommend to use the UnsupportedOperationException.

因此,我建议使用UnsupportedOperationException