title: How to catch the task exception in java fx application?
body: <pre><code>import java.util.concurrent.ExecutionException;
  import java.util.concurrent.ExecutorService;
  import java.util.concurrent.Executors;
  import java.util.concurrent.Future;
  
  import javafx.concurrent.Task;
  
  
  public class T {
  
      public static void main(String[] args) {
  
          ExecutorService executorService = Executors.newSingleThreadExecutor();
  
          Task t = new Task(){
  
              @Override
              protected Object call() throws Exception {
                  System.out.println(1/0);
                  return null;
              }
  
          };
  
          //My progresss Bar in JavaFX
          //Progressbar.progressProperty().bind(t.progressProperty());
  
          Future future = executorService.submit(t);
  
          try {
              future.get();
          } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (ExecutionException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }  //returns null if the task has finished correctly.
  
          executorService.shutdown();
  
  
  }
  }
  </code></pre>
  
  <p>I have a code that resembles something like this my code task has internal method call in object call that throws sql exception but i can never catch it in the Executor service also just above the submit call i have a progressbar of javafx but that also seems to get stuck like the main ui hangs when using future . without future the progress bar works.</p>