Java SQLException throwException(final Throwable t)

Here you can find the source of throwException(final Throwable t)

Description

Examine a Throwable to preserve RuntimeException and Error, otherwise throw a SQLException.

License

Apache License

Parameter

Parameter Description
t The exception. Ignored if <tt>null</tt>.

Exception

Parameter Description
SQLException The exception.

Declaration

static final void throwException(final Throwable t) throws SQLException 

Method Source Code


//package com.java2s;
/*//  w w  w.j a v a2 s . c o m
 * Copyright 2010 Attribyte, LLC 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and limitations under the License.  
 * 
 */

import java.sql.SQLException;

public class Main {
    /**
     * Examine a <tt>Throwable</tt> to preserve <tt>RuntimeException</tt> and <tt>Error</tt>, otherwise throw a <tt>SQLException</tt>.
     * @param t The exception. Ignored if <tt>null</tt>.
     * @throws SQLException The exception.
     */
    static final void throwException(final Throwable t) throws SQLException {
        throwException(t, null);
    }

    /**
     * Examine a <tt>Throwable</tt> to preserve <tt>RuntimeException</tt> and <tt>Error</tt>, otherwise throw a <tt>SQLException</tt>.
     * @param t The exception. Ignored if <tt>null</tt>.
     * @param message A message to be added to the <tt>SQLException</tt>.
     * @throws java.sql.SQLException The exception.
     */
    static final void throwException(final Throwable t, final String message) throws SQLException {
        if (t != null) {
            if (t instanceof SQLException) {
                throw (SQLException) t;
            } else if (t instanceof Error) {
                throw (Error) t;
            } else if (t instanceof RuntimeException) {
                throw (RuntimeException) t;
            } else {
                if (message != null) {
                    throw new SQLException(message, t);
                } else {
                    throw new SQLException(t);
                }
            }
        }
    }
}

Related

  1. printSQLExceptionToErrorLog(Log logger, String message, List sqlExceptions)
  2. printStackTrace(final Throwable exception)
  3. printStackTrace(SQLException e)
  4. retrieveDetailException(Throwable throwable)
  5. rollbackTransaction(final Connection conn, final SQLException e)
  6. throwException(String message)
  7. toSQLException(Throwable e)
  8. unboxException(SQLException exception)