getName() 是一个简单的示例,因此每个代码都得到了这种处理(这极大地使代码膨胀,但它确实有效!)
@Override
public String getName() throws RemoteException, NotesException {
java.util.concurrent.Callable<String> callableRoutine =
new java.util.concurrent.Callable<String>() {
@Override
public String call() throws java.rmi.RemoteException, NotesException {
return lnView.getName();
}
};
try {
return executor.submit(callableRoutine).get();
} catch (Exception ex) {
handleExceptions(ex);
return null; // not used
}
}
/**
* Handle exceptions from serializing to a thread.
*
* This routine always throws an exception, does not return normally.
*
* @param ex
* @throws java.rmi.RemoteException
* @throws NotesException
*/
private void handleExceptions(Throwable ex) throws java.rmi.RemoteException, NotesException {
if (ex instanceof ExecutionException) {
Throwable t = ex.getCause();
if (t instanceof java.rmi.RemoteException) {
throw (java.rmi.RemoteException) ex.getCause();
} else if (t instanceof NotesException) {
throw (NotesException) ex.getCause();
} else {
throw new NotesException(LnRemote.lnErrorRmi, utMisc.getExceptionMessageClean(t), t);
}
} else {
throw new NotesException(LnRemote.lnErrorRmi, utMisc.getExceptionMessageClean(ex), ex);
}
}