En .net, la clase AggregateException le permite lanzar una excepción que contiene múltiples excepciones.¿Cuál es el equivalente de Java de AggregateException de .net?
Por ejemplo, le gustaría arrojar una excepción agregada si ejecutó varias tareas en paralelo y algunas de ellas fallaron con excepciones.
¿Java tiene una clase equivalente?
El caso específico quiero utilizarlo en:
public static void runMultipleThenJoin(Runnable... jobs) {
final List<Exception> errors = new Vector<Exception>();
try {
//create exception-handling thread jobs for each job
List<Thread> threads = new ArrayList<Thread>();
for (final Runnable job : jobs)
threads.add(new Thread(new Runnable() {public void run() {
try {
job.run();
} catch (Exception ex) {
errors.add(ex);
}
}}));
//start all
for (Thread t : threads)
t.start();
//join all
for (Thread t : threads)
t.join();
} catch (InterruptedException ex) {
//no way to recover from this situation
throw new RuntimeException(ex);
}
if (errors.size() > 0)
throw new AggregateException(errors);
}
No estoy al tanto de uno. Sin embargo, nunca he buscado uno tampoco. – Powerlord