0

Callable.call() forces us to catch Exception.

Basically we have to "Drop to frame" (eclipse) to see the exception happening in the exact place, but sometimes the preconditions are already gone (some field values were already set preventing proper debugging, making it a boring task).

My first thought was use Runnable, but run() wont return a value, mostly when I want to optionally run on the same thread or on a new thread dynamically.
So, My "great idea" was to create a "NewCallable" but its call() would NOT throw exception, so debug would stop where it actually happens...

The point is, will other functionalities in java like FutureTask (I havent tried it yet tho), and may be some other, that depend on Callable or Runnable, later on, make my work more difficult by not using Callable?

May be should I extend Runnable instead, but the return value?

Or could I suppress Callable.call() and use another method, but that still could break other java functionalities.

What would be the best option to let us debug easily in the exact point things happen during a call()?

Aquarius Power
  • 3,729
  • 5
  • 32
  • 67
  • no, don't use Runnable. Instead when you call `get()` on your Future when the Callable has completed its actions, all exceptions can be caught at that time. – Hovercraft Full Of Eels Sep 03 '16 at 22:17
  • @HovercraftFullOfEels but in case I am optionally running on the same thread, just calling caller.call(), if I use the Callable interface, I am forced to catch Exception, what will prevent me from debugging on the spot. Or you mean I can use FutureTask to call it without catch Exception on the same thread? – Aquarius Power Sep 03 '16 at 22:31
  • ???? Now you're confusing me. If you call the `call()` method, what's preventing you from putting it within a try/catch block and then handling the exception if thrown? – Hovercraft Full Of Eels Sep 03 '16 at 22:37
  • @HovercraftFullOfEels the problem is call() requires catch for "Exception" (and not specific ones). I use a queue, and I may run it in another thread or in the same main thread. If I run it in the same main thread, and I am forced to catch Exception, the exact spot where the specific one happened is beyond debug now, I will have to drop to frame, but then I may not reach that same spot because some variables may have already been modified... Also I do not want to handle these specific exceptions, I need to see them happening in place to fix the code so they will not happen later. (continue) – Aquarius Power Sep 03 '16 at 22:44
  • These exceptions are application breaking (or data messing) and must not be workarounded... – Aquarius Power Sep 03 '16 at 22:44
  • I actually found the solution, I just have to extend Callable and override call() without the throws. I dont know if it can break something later tho. And I dont know if this is really a duplicate because I went there but there are still many thing I dont understand (I havent studied many things there yet, I need time to make it sure). – Aquarius Power Sep 03 '16 at 23:06

0 Answers0