364
votes

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

4
Is it appropriate to use when a class does not implement a method, but child classes may do so? In other words, to have an abstract method in a non-abstract class. - Sergey Orshanskiy
@SergeyOrshanskiy It's useful for when, depending on how you construct an object, you need to create an anonymous class that implements an interface in order to instantiate a member variable, but you don't want it to be used. If you set it to null and you accidentally used it (or someone else did) you would get NullPointerExceptions which are less obvious than UnsupportedOperationExceptions in this case. Just an example. - 2rs2ts

4 Answers

509
votes

java.lang.UnsupportedOperationException

Thrown to indicate that the requested operation is not supported.

237
votes

Differentiate between the two cases you named:

34
votes

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

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

Therefore, I recommend to use the UnsupportedOperationException.

14
votes

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

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