Here you can find the source of mergeException(List
public static SQLException mergeException(List<SQLException> exceptions)
//package com.java2s; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; public class Main { public static SQLException mergeException(List<SQLException> exceptions) { SQLException first = exceptions.get(0); List<StackTraceElement> stes = new ArrayList<StackTraceElement>(30 * exceptions.size()); for (StackTraceElement ste : first.getStackTrace()) { stes.add(ste);/*from w ww .ja v a 2s . com*/ } //SQLException current = first; Set<SQLException> exceptionsSet = new HashSet<SQLException>(exceptions.size()); exceptionsSet.add(first); for (int i = 1, n = exceptions.size(); i < n; i++) { if (exceptionsSet.contains(exceptions.get(i))) { continue; } //current.setNextException(exceptions.get(i)); //current = exceptions.get(i); exceptionsSet.add(exceptions.get(i)); for (StackTraceElement ste : exceptions.get(i).getStackTrace()) { stes.add(ste); } } //newEx.getCause(); first.setStackTrace(stes.toArray(new StackTraceElement[stes.size()])); return first; } }