Java SQLException getExceptionCause(Throwable e)

Here you can find the source of getExceptionCause(Throwable e)

Description

Gets the cause from an exception.

License

Open Source License

Parameter

Parameter Description
e a <code>Throwable</code> instance

Return

a Throwable instance

Declaration

public static Throwable getExceptionCause(Throwable e) 

Method Source Code

//package com.java2s;
/*/*from  w w w .j av a 2 s .c  om*/
 * Copyright (c) Open Source Strategies, Inc.
 *
 * Opentaps is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Opentaps is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Opentaps.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Gets the cause from an exception.
     *
     * @param e a <code>Throwable</code> instance
     * @return a <code>Throwable</code> instance
     */
    public static Throwable getExceptionCause(Throwable e) {
        if (e instanceof java.sql.SQLException) {
            return e;
        } else if (e instanceof java.sql.BatchUpdateException) {
            return e;
        } else if (e.getCause() != null) {
            return getExceptionCause(e.getCause());
        } else {
            return e;
        }
    }
}

Related

  1. getAllMessages(Throwable t, boolean includeExceptionName)
  2. getAllMessagesArray(Throwable t, boolean includeExceptionName)
  3. getAllSqlExceptionMessages(SQLException t)
  4. getAllSqlExceptionMessagesArray(SQLException t, boolean includeExceptionName)
  5. getClassWhichThrowsException(SQLException e)
  6. getExceptionMessage(Throwable t)
  7. getFullMessage(SQLException exception)
  8. getNextExceptionFromLastCause(Exception e)
  9. getSingleSQLExceptionCause(SQLException e)