Java SQLException retrieveDetailException(Throwable throwable)

Here you can find the source of retrieveDetailException(Throwable throwable)

Description

Returns an instance of SQLException containing detailed error information

License

Open Source License

Parameter

Parameter Description
throwable a parameter

Declaration

public static SQLException retrieveDetailException(Throwable throwable) 

Method Source Code

//package com.java2s;
/***********************************************************************************************************************
 * Copyright (c) 2009 Sybase, Inc. All rights reserved. This program and the accompanying materials are made available
 * under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * /*from ww w  .  j a v  a2s  .  c  o  m*/
 * Contributors: Sybase, Inc. - initial API and implementation
 **********************************************************************************************************************/

import java.sql.SQLException;

public class Main {
    /**
     * Returns an instance of <code>SQLException</code> containing detailed error information
     * 
     * @param throwable
     * @return
     */
    public static SQLException retrieveDetailException(Throwable throwable) {
        String lineSep = System.getProperty("line.separator");
        if (throwable != null) {
            StringBuffer msg = new StringBuffer("");
            if (throwable.getLocalizedMessage() != null) {
                msg.append(throwable.getLocalizedMessage());
            } else {
                msg.append(throwable.getMessage());
            }
            if (throwable instanceof SQLException) {
                SQLException sqlEx = (SQLException) throwable;
                while (sqlEx.getNextException() != null) {
                    sqlEx = sqlEx.getNextException();
                    if (sqlEx.getLocalizedMessage() != null) {
                        msg.append("").append(lineSep).append(sqlEx.getLocalizedMessage());
                    } else {
                        msg.append("").append(lineSep).append(sqlEx.getMessage());
                    }
                }
            }
            return new SQLException(msg.toString());
        }
        return null;
    }
}

Related

  1. printSQLException(SQLException ex)
  2. printSqlException(SQLException sqlex)
  3. printSQLExceptionToErrorLog(Log logger, String message, List sqlExceptions)
  4. printStackTrace(final Throwable exception)
  5. printStackTrace(SQLException e)
  6. rollbackTransaction(final Connection conn, final SQLException e)
  7. throwException(final Throwable t)
  8. throwException(String message)
  9. toSQLException(Throwable e)