12 Haziran 2023 Pazartesi

ExecutionException Sınıfı

Giriş
Şu satırı dahil ederiz
import java.util.concurrent.ExecutionException;
Açıklaması şöyle
Exception thrown when attempting to retrieve the result of a task that aborted by throwing an exception. This exception can be inspected using the Throwable.getCause() method.
Örnek
Şöyle yaparız
FutureTask futureTask = new FutureTask(() -> {
  // Throw an exception to simulate an error during execution
  throw new RuntimeException("An error occurred during task execution");
});
Thread thread = new Thread(futureTask);

// Start the thread
thread.start();


try {
  // Wait for the thread to complete
  futureTask.get();
} catch (ExecutionException e) {
  System.out.println("ExecutionException");
} 
... 

Hiç yorum yok:

Yorum Gönder