3/09/2008

UnsupportedOperationException and OperationNotSupportedException

For some unimplemented methods, I want to throw some exception instead of leaving it blank. I know there is already such a class in Java but don't know its exact name. So I typed "Operation" and then Ctrl-Space to let NetBeans to complete it. But only javax.naming.OperationNotSupportedException showed up, which is not what I want. After some search, it turns out the right class is java.lang.UnsupportedOperationException. Description from its javadoc:
java.lang.Object
extended by java.lang.Throwable
extended by java.lang.Exception
extended by java.lang.RuntimeException
extended by java.lang.UnsupportedOperationException
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
HeadlessException, ReadOnlyBufferException

public class UnsupportedOperationException
extends RuntimeException

Thrown to indicate that the requested operation is not supported.

This class is a member of the Java Collections Framework.

Since:
1.2