2
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();
}
}
我有一個類似於這樣的代碼我的代碼任務在對象調用中有引發sql異常的內部方法調用,但我無法在Executor服務中捕獲它也在提交調用上方我有一個javafx進度條但也似乎像使用未來的主要用戶界面一樣陷入困境。沒有未來的進度條的作品。如何在java fx應用程序中捕獲任務異常?