Java SQLException mergeException(List exceptions)

Here you can find the source of mergeException(List exceptions)

Description

merge Exception

License

Open Source License

Declaration

public static SQLException mergeException(List<SQLException> exceptions) 

Method Source Code


//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;
    }
}

Related

  1. log(Logger logger, SQLException e)
  2. log(SQLException e, Logger log)
  3. logAll(Log log, SQLException e)
  4. logSqlError(SQLException ex, Logger logger)
  5. mergeException(List exceptions)
  6. mergeSQLExceptionMsg(final StringBuilder msgBuilder, final SQLException e, final String prefix)
  7. oracleSessionHasBeenKilled(Exception exception)
  8. parseRemoteException(Throwable t)
  9. printExceptionAndRollback(Connection conn, Exception e)