I have a Java class which handles both single valued and multi-valued data. Therefore, it exposes two methods: getValue()
and getValues()
. However, I want to throw some kind of exception when the getValue
method is called for multi-valued data. What is the most relevant exception class that I can use? I feel IllegalAccessException
is not appropriate, because I am not using reflection, or any such discovery technique; neither is IllegalArgumentException
appropriate because I am not passing any argument as such.
UnsupportedOperationException
- most common and versatile unchecked run-time exception in Java.
http://docs.oracle.com/javase/6/docs/api/java/lang/UnsupportedOperationException.html