在.net中,AggregateException类允许您引发包含多个异常的异常。什么是来自.net的AggregateException的Java等价物?
例如,如果您并行运行多个任务,并且其中一些任务因异常而失败,您将希望抛出一个AggregateException。
java有一个等价的类吗?
的具体情况下,我想使用它:
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);
}
,我不知道一个内置。但是,我从来没有找过一个。 – Powerlord 2010-07-30 20:08:08