dev*_*ium 525 .net java exception
NotImplementedExceptionJava中是否有类似.NET的东西?
Rav*_*lau 503
Commons Lang有它.或者你可以扔一个UnsupportedOperationException.
Chr*_*ail 280
我认为这java.lang.UnsupportedOperationException就是你要找的东西.
Rea*_*oid 54
你可以自己做(这就是我所做的) - 为了不被异常处理所困扰,你只需要扩展RuntimeException,你的类看起来像这样:
public class NotImplementedException extends RuntimeException {
private static final long serialVersionUID = 1L;
public NotImplementedException(){}
}
Run Code Online (Sandbox Code Playgroud)
您可以扩展它以接收消息 - 但如果您像我一样使用该方法(即,作为提醒,仍有一些东西需要实现),那么通常不需要其他消息.
我敢说,我只使用这种方法,而我正在开发一个系统,让我更容易忘记哪些方法仍未正确实施:)
如前所述,JDK没有紧密匹配。但是,我的团队有时也会使用这种例外情况。我们可以UnsupportedOperationException按照其他答案的建议进行操作,但是我们更喜欢基库中的自定义异常类,该类已弃用构造函数:
public class NotYetImplementedException extends RuntimeException
{
/**
* @deprecated Deprecated to remind you to implement the corresponding code
* before releasing the software.
*/
@Deprecated
public NotYetImplementedException()
{
}
/**
* @deprecated Deprecated to remind you to implement the corresponding code
* before releasing the software.
*/
@Deprecated
public NotYetImplementedException(String message)
{
super(message);
}
}
Run Code Online (Sandbox Code Playgroud)
这种方法具有以下优点:
NotYetImplementedException,他们知道实施是已计划的,或者被遗忘或仍在进行中,而UnsupportedOperationException(根据收款合同)说,永远也不会实施。这就是为什么我们在类名中使用单词“ yet”的原因。而且,IDE可以轻松列出呼叫站点。import在线上(尽管JDK 9 修复了此问题)。| 归档时间: |
|
| 查看次数: |
148863 次 |
| 最近记录: |