List of usage examples for java.sql SQLException getNextException
public SQLException getNextException()
SQLException
object by setNextException(SQLException ex). From source file:Util.java
/** * Looks up and returns the root cause of an exception. If none is found, returns * supplied Throwable object unchanged. If root is found, recursively "unwraps" it, * and returns the result to the user.//from w w w .j a v a2 s. co m */ public static Throwable unwindException(Throwable th) { if (th instanceof SAXException) { SAXException sax = (SAXException) th; if (sax.getException() != null) { return unwindException(sax.getException()); } } else if (th instanceof SQLException) { SQLException sql = (SQLException) th; if (sql.getNextException() != null) { return unwindException(sql.getNextException()); } } else if (th.getCause() != null) { return unwindException(th.getCause()); } return th; }
From source file:hoot.services.utils.ReviewUtils.java
/** * Handles all thrown exceptions from review services * * @param e//from w ww. j av a2 s . co m * a thrown exception * @param errorMessageStart * text to prepend to the error message * //TODO: go through and clean out these message text checks */ public static void handleError(Exception e, String errorMessageStart) { Status status = null; if (!StringUtils.isEmpty(e.getMessage())) { if (e.getMessage().contains("Invalid input parameter") || e.getMessage().contains("Invalid reviewed item") || e.getMessage().contains("Error parsing unique ID tag") || e.getMessage().contains("empty String") || e.getMessage().contains("Invalid coordinate")) { status = Status.BAD_REQUEST; } else if (e.getMessage().contains("record exists") || e.getMessage().contains("records exist") || e.getMessage().contains("to be updated does not exist") || e.getMessage().contains("does not exist")) { status = Status.NOT_FOUND; } else if (e.getMessage().contains("Invalid version") || e.getMessage().contains("Invalid changeset ID") || e.getMessage().contains("references itself") || e.getMessage().contains("Changeset maximum element threshold exceeded") || e.getMessage().contains("was closed at") || e.getMessage().contains("has become out of sync")) { status = Status.CONFLICT; } else if (e.getMessage().contains("exist specified for") || e.getMessage().contains("exist for") || e.getMessage().contains("is still used by")) { status = Status.PRECONDITION_FAILED; } } if (status == null) { status = Status.INTERNAL_SERVER_ERROR; } String message = "Error " + errorMessageStart + ": "; if ((e.getMessage() != null) && e.getMessage().contains("empty String")) { // added for giving a better error message when passing invalid params to jersey message += "Invalid input parameter"; } else { message += e.getMessage(); } if (e instanceof SQLException) { SQLException sqlException = (SQLException) e; if (sqlException.getNextException() != null) { message += " " + sqlException.getNextException().getMessage(); } } if (e.getCause() instanceof SQLException) { SQLException sqlException = (SQLException) e.getCause(); if (sqlException.getNextException() != null) { message += " " + sqlException.getNextException().getMessage(); } } String exceptionCode = status.getStatusCode() + ": " + status.getReasonPhrase(); logger.error("{} {}", exceptionCode, message, e); throw new WebApplicationException(e, Response.status(status).entity(message).build()); }
From source file:sos.util.SOSExceptionMessage.java
/** * /* w ww .java2 s .c o m*/ * * @param exception * @return */ public static String getExceptionMessage(Exception exception) { String msg = ""; try { if (exception instanceof SQLException) { //|| exception instanceof javax.mail.MessagingException) { SQLException sqlExcep = (SQLException) exception; while (sqlExcep != null) { if (sqlExcep.equals(sqlExcep.getNextException())) { break; } msg = sqlExcep.toString(); if (sqlExcep.getCause() != null) { msg = msg + "\n" + sqlExcep.getCause(); } sqlExcep = sqlExcep.getNextException(); } } else { msg = exception.toString(); if (exception.getCause() != null) { msg = exception.toString() + " " + exception.getCause(); } } } catch (Exception e) { System.out.print(e); } return msg; }
From source file:org.rhq.core.util.jdbc.JDBCUtil.java
public static String convertSQLExceptionToString(SQLException e) { StringBuilder result = new StringBuilder(e.toString()); if (e.getNextException() != null) { result.append(" - causes:"); SQLException cause = e;/*w ww . j av a 2s .c o m*/ while ((cause = cause.getNextException()) != null) { result.append("\n\t").append(e); } } return result.toString(); }
From source file:com.google.gerrit.server.schema.H2AccountPatchReviewStore.java
private static String getSQLState(SQLException err) { String ec;/*from w ww . j a va 2 s. c o m*/ SQLException next = err; do { ec = next.getSQLState(); next = next.getNextException(); } while (ec == null && next != null); return ec; }
From source file:io.cloudslang.content.database.utils.SQLUtils.java
public static String toString(SQLException e) { String curr = exceptionToString(e) + "\nstate:" + e.getSQLState(); while ((e = e.getNextException()) != null) curr += "\n\n" + exceptionToString(e) + "\nstate:" + e.getSQLState(); return curr;/*from w ww . j a v a2 s . co m*/ }
From source file:io.cloudslang.content.database.utils.SQLUtils.java
/** * Some databases (Sybase) throw exceptions during a database restore. This function processes that exception, and if it is that type, builds up the output of the command * * @param e The exception to analyze/* ww w. j a v a 2 s . co m*/ * @return The output of the dump command * @throws java.sql.SQLException If it was not a successful load command's exception. */ public static String processLoadException(SQLException e) throws SQLException { final String sqlState = e.getSQLState(); if (sqlState != null && StringUtils.equalsIgnoreCase(sqlState, "s1000")) { SQLException f = e; StringBuilder s = new StringBuilder(); s.append(f.getMessage()); while ((f = f.getNextException()) != null) s.append("\n").append(f.getMessage()); String str = s.toString(); if (StringUtils.containsIgnoreCase(str, "load is complete")) return str; } throw e; }
From source file:io.cloudslang.content.database.utils.SQLUtils.java
/** * Some databases (Sybase) throw exceptions during a database dump. This function processes that exception, and if it is that type, builds up the output of the command * * @param sqlException The exception to analyze * @return The output of the dump command * @throws java.sql.SQLException If it was not a successful dump command's exception. */// w ww. j av a 2s.c o m public static String processDumpException(SQLException sqlException) throws SQLException { final String sqlState = sqlException.getSQLState(); if (sqlState != null && StringUtils.equalsIgnoreCase(sqlState, "s1000")) { SQLException f = sqlException; StringBuilder s = new StringBuilder(); s.append(f.getMessage()); while ((f = f.getNextException()) != null) { s.append("\n").append(f.getMessage()); } String str = s.toString(); if (StringUtils.containsIgnoreCase(str, "dump is complete")) return str; } throw sqlException; }
From source file:com.google.gerrit.server.schema.H2AccountPatchReviewStore.java
public static OrmException convertError(String op, SQLException err) { switch (getSQLStateInt(err)) { case 23001: // UNIQUE CONSTRAINT VIOLATION case 23505: // DUPLICATE_KEY_1 return new OrmDuplicateKeyException("ACCOUNT_PATCH_REVIEWS", err); default:/* w ww . j a v a 2s. c o m*/ if (err.getCause() == null && err.getNextException() != null) { err.initCause(err.getNextException()); } return new OrmException(op + " failure on ACCOUNT_PATCH_REVIEWS", err); } }
From source file:org.objectstyle.cayenne.util.Util.java
/** * Looks up and returns the root cause of an exception. If none is found, * returns supplied Throwable object unchanged. If root is found, * recursively "unwraps" it, and returns the result to the user. *//*from w ww.j a v a 2 s . c o m*/ public static Throwable unwindException(Throwable th) { if (th instanceof CayenneException) { CayenneException e = (CayenneException) th; if (e.getCause() != null) { return unwindException(e.getCause()); } } else if (th instanceof CayenneRuntimeException) { CayenneRuntimeException e = (CayenneRuntimeException) th; if (e.getCause() != null) { return unwindException(e.getCause()); } } else if (th instanceof InvocationTargetException) { InvocationTargetException e = (InvocationTargetException) th; if (e.getTargetException() != null) { return unwindException(e.getTargetException()); } } else if (th instanceof SAXException) { SAXException sax = (SAXException) th; if (sax.getException() != null) { return unwindException(sax.getException()); } } else if (th instanceof SQLException) { SQLException sql = (SQLException) th; if (sql.getNextException() != null) { return unwindException(sql.getNextException()); } } return th; }