In .net la classe AggregateException consente di generare un'eccezione contenente più eccezioni.Qual è l'equivalente java di AggregateException da .net?
Ad esempio, si vorrebbe lanciare un AggregateException se si eseguono più attività in parallelo e alcune di esse non sono riuscite con eccezioni.
java ha una classe equivalente?
Il caso specifico che voglio utilizzare in:
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);
}
Io non sono a conoscenza di una. Tuttavia, non ne ho mai cercato neanche uno. – Powerlord