MultiRuntimeException extends RuntimeException { public static MultiRuntimeException get(Collection<Throwable> sources) { if (sources == null || sources.size() == 0) { return new MultiRuntimeException( "MultiRuntimeException thrown with no sources!", new RuntimeException()); } StringBuilder msgBuilder = new StringBuilder(); msgBuilder .append("Multiple remote exceptions thrown. Stack trace to first included, rest in message below.\n"); int traceNum = 1; for (Throwable t : sources) { if (traceNum > 1) { msgBuilder.append(String.format("Exception %d\n", traceNum)); msgBuilder.append(t.getClass().getName()); msgBuilder.append("\n"); msgBuilder.append(t.getMessage()); msgBuilder.append("\n"); for (StackTraceElement element : t.getStackTrace()) { msgBuilder.append(String.format("\t%s:%d %s\n", element.getClassName(), element.getLineNumber(), element.getMethodName())); } } traceNum++; } return new MultiRuntimeException(msgBuilder.toString(), sources.iterator() .next()); } private  MultiRuntimeException(String message, Throwable firstSource); static MultiRuntimeException get(Collection<Throwable> sources);  }
@Test public void testEmptyMultiRuntimeException() { List<Throwable> list = new ArrayList<Throwable>(); Assert.assertNotNull(MultiRuntimeException.get(null)); Assert.assertNotNull(MultiRuntimeException.get(list)); }