title: How can I throw an exception within ListeningExecutorService?
body: <p>I used ListeningExecutorService of guava in my project, got confused about the exception handling.</p>
  
  <p>I used a thread pool, submit a task to it, and set a timeout to the listenableFuture, and add a callback to it.</p>
  
  <pre><code> final ListeningExecutorService threadPool = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
  
  
  
   Futures.addCallback(listenableFuture, new FutureCallback&lt;**&gt;() {
  
          @Override
          public void onSuccess(@Nullable ** data) {
              xxxxxxx;
          }
  
          public void onFailure(Throwable t) {
              xxxxxxxxxx;
              if (t instanceof CancellationException) {
                  throw new QueryException("yyyy");
              } else {
                  throw new QueryException("zzzzz");
              }
          }
      });
  </code></pre>
  
  <p>I can't catch the exception inside the callback. So I use another ListenableFuture to get the exception</p>
  
  <pre><code> ListenableFuture allFutures = Futures.allAsList(allFuturesList);
          try {
              allFutures.get();
          } catch (CancellationException ce) {
              throw new QueryException("");
          } catch (InterruptedException t) {
              throw new QueryException("");
          } catch (ExecutionException e) {
              Throwable t = e.getCause();
              if (t instanceof QueryException)
                  throw (QueryException) t;
              else
                  throw new QueryException();
          } catch (QueryException qe) {
              throw qe;
          } catch (Exception e) {
              throw new QueryException();
          } finally {
          }
  </code></pre>
  
  <p>But I when the callback throw a QueryException, the allFutures can't catch it, allFutures can only catch a CancellationException without the detail error message.</p>
  
  <p>How can I get my detail error message?</p>