I don;t quite understand where I can throw this exception.
For instance, I\'m implementing the Future
interface and don\'t want anyone calls t
Technically UnsupportedOperationException is unchecked, and therefore can be thrown anywhere you like. However throwing it in unexpected places will cause your class to be less easy to use, and is not recommended.
The place where UnsupportedOperationException is expected to be thrown is in "optional operations". The Java framework contains plenty of these, especially in the Collections framework. For example "add" is an optional operation, because immutable collections should not allow it. Throwing UnsupportedOperationException is exactly what you should do if you don't want to write one of these methods.
In your case timed "get" is pretty fundamental to the use of Future, and you will cause some surprise if you don't implement it. if you are going to do that, make sure it is well documented, and be aware that this will cause your implementation of Future to be unusable in some cases, and to potentially cause a program that uses it to crash.
If you simply don't have the resources to write a timed get for your implementation of Future, consider using an implementation that already exists, such as extending your class from FutureTask.