Reputation: 63
Should I throw exception from call() method of callable class? If no, why not? What is the possible drawbacks?
I have a call method and in it another class is called. Another class throws exception and it is highly related with a clas which running callable method and gets its outputs. Should I handle exception in call method or rethrow it?
Upvotes: 0
Views: 1446
Reputation: 692191
You should deal with exceptions in Callable's call()
method the same way as you deal with them everywhere else.
A Callable represents a task to perform. If you consider that the task must fail when you get this exception, then throw it (or throw another exception wrapping it).
If you consider that the task must succeed despite this exception, then catch it and deal with it.
The javadoc of the call()
method says:
Computes a result, or throws an exception if unable to do so.
Upvotes: 2