public static SQLException toSQLException(String msg, String sqlState, Throwable t) { if (t instanceof SQLException) { if (Debug.DEBUG && Debug.TRACE == Debug.TRACE_MAX && logger.isLoggable(MLevel.FINER)) { SQLException s = (SQLException) t; StringBuffer tmp = new StringBuffer(255); tmp.append("Attempted to convert SQLException to SQLException. Leaving it alone."); tmp.append(" [SQLState: "); tmp.append(s.getSQLState()); tmp.append("; errorCode: "); tmp.append(s.getErrorCode()); tmp.append(']'); if (msg != null) tmp.append(" Ignoring suggested message: '" + msg + "'."); logger.log(MLevel.FINER, tmp.toString(), t); SQLException s2 = s; while ((s2 = s2.getNextException()) != null) logger.log(MLevel.FINER, "Nested SQLException or SQLWarning: ", s2); } return (SQLException) t; } else { if (Debug.DEBUG) { // t.printStackTrace(); if (logger.isLoggable(MLevel.FINE)) logger.log(MLevel.FINE, "Converting Throwable to SQLException...", t); } if (msg == null) msg = "An SQLException was provoked by the following failure: " + t.toString(); if (VersionUtils.isAtLeastJavaVersion14()) { SQLException out = new SQLException(msg); out.initCause(t); return out; } else return new SQLException( msg + System.getProperty("line.separator") + "[Cause: " + ThrowableUtils.extractStackTrace(t) + ']', sqlState); } }
/** * Convert an exception to a fulltext exception. * * @param e the original exception * @return the converted SQL exception */ protected static SQLException convertException(Exception e) { SQLException e2 = new SQLException("Error while indexing document", "FULLTEXT"); e2.initCause(e); return e2; }