Is there anything like .NET's NotImplementedException in Java?
Is there anything like .NET's NotImplementedException in Java?
As mentioned, the JDK does not have a close match. However, my team occasionally has a use for such an exception as well. We could have gone with UnsupportedOperationException as suggested by other answers, but we prefer a custom exception class in our base library that has deprecated constructors:
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);
}
}
This approach has the following benefits:
NotYetImplementedException, they know that an implementation was planned and was either forgotten or is still in progress, whereas UnsupportedOperationException says (in line with collection contracts) that something will never be implemented. That's why we have the word "yet" in the class name. Also, an IDE can easily list the call sites.import line (JDK 9 fixed this, though).In the spirit of Stackoverflow being a combination of Reddit and Wikipedia, here's some additional information, which is relevant to the question, and can also be an answer to the question.
When you ask NetBeans IDE to create a missing implementation, it uses a UnsupportedOperationException:
void setPropertiesWithReader(IDataReader rdr)
{
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
If it's good enough for NetBeans, it's good enough for us.