Leifo (5) [Avatar] Offline
#1
Hi,
I am having some troubles using the exception introduction pattern for the thread safety program in chapter 9. Page 312.
I need some more tips about what to do for the synchronous part. I always get a InvocationTargetException, caught in the catch block after invokeAndWait().
Any help appreciated.

Leifo
ramnivas (171) [Avatar] Offline
#2
Re: Question about exception introduction
Hi Leifo,

InvocationTargetException exception is thrown by invokeAndWait() when the runnable passed to it throws an exception.

Can you show the code you are using? It might help to
understand the problem and provide you a solution.

-Ramnivas
Leifo (5) [Avatar] Offline
#3
Re: Question about exception introduction
Object around()
: routedMethods()
&& (!voidReturnValueCalls() || uiSyncMethodCalls()) {
RunnableWithReturn worker = new RunnableWithReturn() {
public void run() {
_returnValue = proceed();
}};
try {
EventQueue.invokeAndWait(worker);
} catch (Exception ex) {
Throwable cause = ex.getCause();//added
if (cause instanceof TalException) {//added
throw new MyRuntimeException(cause);//adde
}
// ... log exception
return null;
}
return worker.getReturnValue();
}

I added this (see above)
Throwable cause = ex.getCause();
if (cause instanceof TalException) {
throw new MyRuntimeException(cause);
//throw (MyCheckedException)grunn;
}
to the last advice in listing 9.10, after posting my first question. And this seems to work. Do you think this is how it should be done?

Leifo
ramnivas (171) [Avatar] Offline
#4
Re: Question about exception introduction
Yes, the scheme you have utilized seems right.

-Ramnivas