Illegal method called

Neel picture Neel · Apr 1, 2012 · Viewed 7.2k times · Source

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.

Answer

user719662 picture user719662 · Apr 1, 2012

UnsupportedOperationException - most common and versatile unchecked run-time exception in Java.

http://docs.oracle.com/javase/6/docs/api/java/lang/UnsupportedOperationException.html