2

I'm using Volley to make synchronous requests to a server. The following is how I'd make a synchronous request --

RequestFuture<JSONObject> future = RequestFuture.newFuture();
JsonObjectRequest request = new JsonObjectRequest("http://my-url.com", future, future);
requestQueue.add(request);

try {
    JSONObject response = future.get();
} catch (InterruptedException e) {
} catch (ExecutionException e) {
    // Handle exceptions.
}

There are various reasons that this could fail - server errors, timeouts, malformed url exceptions, etc and I'm wondering if there is a way for me to determine the specific cause of failure. It looks like ExecutionException wraps all of the various exceptions that could be thrown, but I'd rather not have a bunch of executionException.getCause() instanceOf FooException calls to determine the failure reason. Is there a cleaner way to determine the cause of failure?

Matthew
  • 6,356
  • 9
  • 47
  • 59
  • Sorry, this is a duplicate of [What is the best way to handle an ExecutionException?](http://stackoverflow.com/questions/10437890/what-is-the-best-way-to-handle-an-executionexception) – Matthew Jul 18 '13 at 00:23

0 Answers0