List of usage examples for java.lang Throwable getCause
public synchronized Throwable getCause()
From source file:com.tussle.main.Utility.java
public static JsonValue exceptionToJson(Throwable ex) { JsonValue topValue = new JsonValue(JsonValue.ValueType.object); JsonValue exceptionClass = new JsonValue(ex.getClass().toString()); topValue.addChild("Exception Class", exceptionClass); if (ex.getLocalizedMessage() != null) { JsonValue exceptionMessage = new JsonValue(ex.getLocalizedMessage()); topValue.addChild("Exception Message", exceptionMessage); }/*from w ww . jav a2 s .c o m*/ if (ex.getCause() != null) { JsonValue exceptionCause = new JsonValue(ex.getCause().toString()); topValue.addChild("Exception Cause", exceptionCause); } JsonValue stackTrace = new JsonValue(JsonValue.ValueType.array); for (StackTraceElement element : ex.getStackTrace()) stackTrace.addChild(new JsonValue(element.toString())); topValue.addChild("Stack Trace", stackTrace); return topValue; }
From source file:de.alpharogroup.exception.ExceptionExtensions.java
/** * Gets the stack trace elements from the given Throwable and returns a {@link String} object * from it./*from w w w. j a v a2 s. co m*/ * * @param throwable * the throwable * @return the stack trace elements */ public static String getStackTraceElements(Throwable throwable) { StringWriter sw = null; PrintWriter pw = null; String stacktrace = "throwable is null..."; if (throwable != null) { try { sw = new StringWriter(); pw = new PrintWriter(sw); pw.println(throwable.getClass().toString()); while (throwable != null) { pw.println(throwable); final StackTraceElement[] stackTraceElements = throwable.getStackTrace(); for (final StackTraceElement stackTraceElement : stackTraceElements) { pw.println("\tat " + stackTraceElement); } throwable = throwable.getCause(); if (throwable != null) { pw.println("Caused by:\r\n"); } } stacktrace = sw.toString(); } finally { StreamExtensions.closeWriter(sw); StreamExtensions.closeWriter(pw); } } return stacktrace; }
From source file:org.ambraproject.admin.action.AdminTopAction.java
/** * Extract the message string from an exception object. * * @param t The throwable containing the message that will be extracted. * @return message string//from w w w . ja v a2 s. c om */ private static String getMessages(Throwable t) { StringBuilder msg = new StringBuilder(); while (t != null) { msg.append(t.toString()); t = t.getCause(); if (t != null) msg.append("<br/>\n"); } return msg.toString(); }
From source file:com.salesforce.ide.core.internal.utils.ForceExceptionUtils.java
public static String getConnectionCauseExceptionMessage(ConnectorConfig connectorConfig, Throwable th) { StringBuffer strBuff = null;/*from ww w . j av a2s.c o m*/ if (connectorConfig != null && Utils.isNotEmpty(connectorConfig.getServiceEndpoint())) { strBuff = new StringBuffer(Messages.getString("General.ConnectionError.Server.message", new String[] { Utils.getServerNameFromUrl(connectorConfig.getServiceEndpoint()) })); } else { strBuff = new StringBuffer(Messages.getString("General.ConnectionError.message")); } strBuff.append(":"); if (th.getCause() instanceof UnknownHostException && connectorConfig != null) { return getUnknownHostExceptionMessage(strBuff, connectorConfig, th); } strBuff.append("\n\n").append(th.getCause().getClass().getSimpleName()).append(": ") .append(getStrippedRootCauseMessage(th.getCause())); return strBuff.toString(); }
From source file:edu.osu.ling.pep.Pep.java
/** * Prints a throwable.// w w w.jav a 2s . co m * * @param error * The throwable that was intercepted. * @see #printError(String) */ private static void printError(final Throwable error) { if (error instanceof SAXParseException) { final SAXParseException spe = (SAXParseException) error; Pep.printError("line " + spe.getLineNumber() + ": " + spe.getMessage()); } else { String msg = error.getMessage(); final Throwable cause = error.getCause(); if (cause != null && !cause.equals(error)) { msg += ": " + cause.getMessage(); } Pep.printError(msg); } }
From source file:org.glowroot.central.SyntheticMonitorService.java
private static String getBestMessageForSyntheticFailure(Throwable throwable) { String message = throwable.getMessage(); if (throwable.getClass() == Exception.class && throwable.getCause() == null && message != null) { // special case so synthetic monitors can display a simple error message without the // exception class name clutter return message; } else {//from w w w . j a v a 2 s. c om return Throwables.getBestMessage(throwable); } }
From source file:com.salesforce.ide.core.internal.utils.ForceExceptionUtils.java
public static void handleConnectionException(Connection connection, Throwable th) throws InvalidLoginException, ForceConnectionException, InsufficientPermissionsException { if (th instanceof LoginFault) { throw new InvalidLoginException(getExceptionMessage(th), getExceptionCode(th), connection, th); } else if (isInsufficientPermissionsException(th)) { throwNewInsufficientPermissionsException(connection, th); } else if (th instanceof ApiFault) { throw new ForceConnectionException(getExceptionMessage(th), getExceptionCode(th), connection, th); } else if (th.getCause() != null && connection.getConnectorConfig() != null) { String msg = getConnectionCauseExceptionMessage(connection.getConnectorConfig(), th); throw new ForceConnectionException(msg, connection, th); } else {/*from w w w . j a v a 2s . c om*/ throw new ForceConnectionException(getStrippedRootCauseMessage(th), connection, th); } }
From source file:org.eclipse.cft.server.core.internal.CloudErrorUtil.java
/** * Error due to invalid credentials, typically 401 or 403 HTTP errors. * Returns null if the error is NOT an invalid credentials error. * @param error error to parse//w ww .j av a 2 s. c o m * @return Error message if invalid credentials error (401 or 403), or null. */ public static String getInvalidCredentialsError(Throwable error) { if (isUnauthorisedException(error)) { return Messages.ERROR_WRONG_EMAIL_OR_PASSWORD_UNAUTHORISED; } else if (isForbiddenException(error)) { return Messages.ERROR_WRONG_EMAIL_OR_PASSWORD_FORBIDDEN; } else { OAuth2AccessDeniedException oauthException = null; if (error instanceof OAuth2AccessDeniedException) { oauthException = (OAuth2AccessDeniedException) error; } else if (error.getCause() instanceof OAuth2AccessDeniedException) { oauthException = (OAuth2AccessDeniedException) error.getCause(); } if (oauthException != null) { return NLS.bind(Messages.ERROR_ACCESS_TOKEN, oauthException.getOAuth2ErrorCode()); } } return null; }
From source file:fiftyfive.wicket.util.LoggingUtils.java
/** * Attempts to find the most meaningful exception in a runtime exception * chain by stripping away the exceptions commonly used as "wrappers", * namely: RuntimeException, WicketRuntimeException, * InvocationTargetException and ExecutionException. These four exception * types are usually language cruft that don't add much desciptive value. * <p>/*from w w w. j ava 2s . com*/ * For example, if the exception chain is: * <pre class="example"> * WicketRuntimeException * -> InvocationTargetException * -> MyBusinessException * -> SQLException</pre> * <p> * Then the unwrapped exception would be {@code MyBusinessException}. */ public static Throwable unwrap(Throwable e) { Args.notNull(e, "e"); Throwable unwrapped = e; while (true) { Throwable cause = null; if (unwrapped instanceof WicketRuntimeException || unwrapped instanceof InvocationTargetException || unwrapped instanceof ExecutionException || unwrapped.getClass().equals(RuntimeException.class)) { cause = unwrapped.getCause(); } if (null == cause || unwrapped == cause) { break; } unwrapped = cause; } return unwrapped; }
From source file:kr.co.aim.nanoframe.exception.ErrorSignal.java
public static nanoFrameErrorSignal getNotifyException(Throwable e) { if (e instanceof nanoFrameErrorSignal) return (nanoFrameErrorSignal) e; else if (e instanceof InvocationTargetException) { Throwable cause = ((InvocationTargetException) e).getTargetException(); return getNotifyException(cause); } else if (e instanceof SQLException) { return getNotifyException((SQLException) e, null, null); } else if (e instanceof DataAccessException) { return getNotifyException((DataAccessException) e); } else if (e instanceof NestedRuntimeException) { Throwable cause = ((NestedRuntimeException) e).getMostSpecificCause(); if (cause != null) return new nanoFrameErrorSignal(ErrorSignal.UnexprectedSignal, e.getMessage(), e); else {//from ww w . j a va 2 s . com cause = e.getCause(); if (cause != null) return new nanoFrameErrorSignal(ErrorSignal.UnexprectedSignal, e.getMessage(), e); } } return new nanoFrameErrorSignal(ErrorSignal.UnexprectedSignal, e.getMessage(), e); }