Standard exception when a subclass' method implementation is missing?

exception, java, methods

Solution

I have seen some libraries using UnsupportedOperationException for this.

Thrown to indicate that the requested operation is not supported.

Problem

Context: I have an abstract class `SuperClass`, which has a substantial number of subclasses, each working on a different business object, but in similar fashion. I need to add some new functionality which definitely has its place in `SuperClass`, but will rely on a subclass-specific attribute, that I need to get in the superclass method. The obvious way here is to add an abstract getter in `SuperClass` for the attribute, and have every subclass override it so that it can send the correct attribute when called. The catch is: I am not allowed to change the code of other subclasses than the one I'm working on because of a fear of regressions. So I can't add an abstract method, as the other subclasses would not compile anymore. Since only the object I'm working on now will require this new functionality, I can afford to declare a standard non-abstract method in `SuperClass`, and return `null` there. Then override it in the subclass I'm working on, and voilà. Question: If someone who doesn't read my warnings in the Javadoc properly ever try to call this new method from a different subclass, it will produce unexpected results due to the getter not being properly overriden. Rather than returning `null` (and unexpected results) in `SuperClass`, I think throwing an exception would be more elegant and useful for my fellow programmers. I could define a custom-made exception, but does something along the lines of `YouForgotToImplementSomethingException` or `PleaseReadTheJavadocException` exists in the "standard" exceptions? Edits: Throwing an `Error` as suggested in an answer is not something I'm very fond of, but maybe here it could make sense to emulate the compiler's behavior? Thoughts on this?

Original source