f.get()したときに、ExecutionExceptionが発生する
ExecutionExceptionがsubmit()で発生したExceptionを保有している
class SampleException extends Exception {
public SampleException(String message) {
super(message);
}
public SampleException() {
}
}
public class Outer {
public static void main(String[] args) throws InterruptedException {
ExecutorService e = Executors.newSingleThreadExecutor();
Future f = e.submit(() -> {throw new SampleException("exxxxx");});
e.shutdown();
try {
System.out.println(f.get());
} catch (ExecutionException ex) {
System.out.println(ex.getMessage());
}
}
}
com.mycompany.mavenproject1.SampleException: exxxxx