I want an Error not a RuntimeException. It would be a bug internal to
the class. UnsupportedOperationException is used when a subtype does not
support all the operations of its supertypes, which is not the case
here. And I don't want and fool's catch RuntimeException catching it.
I'm not sure an Error is suitable here - this is a deliberate illegal
access rather than an incompatible runtime class change. Personally I
would use InstantiationException - although not a runtime exception, since
anyone invoking the constructor would be doing so reflectively I don't
think that'd matter too much. I think this case is within the spirit, if
not necessarily the letter, of that exception's spec which says:
"Thrown when an application tries to create an instance of a class using
the newInstance method in class Class, but the specified class object
cannot be instantiated because it is an interface or is an abstract class."
(from 1.5 Javadoc)
In other words, it would make the newInstance method behave as if it was
an abstract or interface class.
You might also consider InstantiationError, but that loses the benefit of
the above and is only thrown, according to it's doc, in case of
incompatible runtime class change.
Does it matter if the exception is caught? What about a bigger fool
catching Throwable?