In particular, is there a standard Exception
subclass used in these circumstances?
There are two types of exceptions in Java: checked (compile time) exceptions and unchecked (runtime) exceptions.
Unchecked exceptions are error conditions that cannot be anticipated and recovered from. They are usually programming errors and cannot be handled at runtime. Unchecked exceptions are subclasses of java.
You can throw a more general exception, or a more specific exception. For simpler methods, more general exceptions are enough. If the method is complex, then, throwing a more specific exception will be reliable.
Runtime - runtime exceptions are internal to your application but are not typically recoverable. For example, an object that is expected to have a value but is actually null. In this case, a NullPointerException exception would be thrown.
java.lang.UnsupportedOperationException
Thrown to indicate that the requested operation is not supported.
Differentiate between the two cases you named:
To indicate that the requested operation is not supported and most likely never will, throw an UnsupportedOperationException
.
To indicate the requested operation has not been implemented yet, choose between this:
Use the NotImplementedException
from apache commons-lang which was available in commons-lang2 and has been re-added to commons-lang3 in version 3.2.
Implement your own NotImplementedException
.
Throw an UnsupportedOperationException
with a message like "Not implemented, yet".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With