List of usage examples for java.lang Throwable getCause
public synchronized Throwable getCause()
From source file:org.bremersee.common.web.client.ResponseErrorHandlerImpl.java
@Override public void handleError(final ClientHttpResponse response) throws IOException { final Throwable t = findThrowable(response); if (t instanceof RuntimeException) { throw (RuntimeException) t; } else {//from w ww . jav a 2 s . c om HttpErrorException e = new HttpErrorException(t.getMessage(), t.getCause()); e.setHttpStatusCode(response.getRawStatusCode()); throw e; } }
From source file:com.thoughtworks.go.agent.AgentController.java
boolean isCausedBySecurity(Throwable e) { if (e == null) { return false; }//from w w w . j a va 2s. c o m if (e instanceof GeneralSecurityException) { return true; } else { return isCausedBySecurity(e.getCause()); } }
From source file:com.flexive.war.beans.admin.main.ScriptConsoleBean.java
/** * Runs the given script code/*from w w w . j a v a2 s . c o m*/ */ public void runScript() { if (StringUtils.isBlank(code)) new FxFacesMsgErr("Script.err.noCodeProvided").addToContext(); else { long start = System.currentTimeMillis(); try { result = runScript(code, "console." + language, web); } catch (Throwable t) { final StringWriter writer = new StringWriter(); t.printStackTrace(new PrintWriter(writer)); final String msg = t.getCause() != null ? t.getCause().getMessage() : t.getMessage(); result = new Formatter().format("Exception caught: %s%n%s", msg, writer.getBuffer()); } finally { executionTime = System.currentTimeMillis() - start; } } }
From source file:fi.mikah.log.LoggingAspect.java
/** * Throw logging.// w ww .j a v a 2 s. c om * * @param joinPoint The join point for the method. * @param callLogging The call logging annotation. * @param throwable The return value of the called method. */ @AfterThrowing(value = "@annotation(callLogging)", argNames = "joinPoint, callLogging, throwable", throwing = "throwable") public void logExitAfterThrowing(final JoinPoint joinPoint, CallLogging callLogging, Throwable throwable) { Logger log = getLogger(joinPoint); Level level = Level.toLevel(callLogging.value().toString()); if (log.isEnabledFor(level)) { log.log(level, "Exiting method " + joinPoint.getSignature().getName() + "[" + throwable.getCause() + "]"); } }
From source file:com.greplin.gec.GecLog4jAppender.java
/** * Writes a formatted exception to the given writer. * * @param message the log message/* w w w.j av a 2s . c o m*/ * @param throwable the exception * @param level the error level * @param out the destination * @throws IOException if there are IO errors in the destination */ void writeFormattedException(final String message, final Throwable throwable, final Level level, final Writer out) throws IOException { JsonGenerator generator = new JsonFactory().createJsonGenerator(out); Throwable rootThrowable = throwable; while (this.passthroughExceptions.contains(rootThrowable.getClass()) && rootThrowable.getCause() != null) { rootThrowable = rootThrowable.getCause(); } generator.writeStartObject(); generator.writeStringField("project", this.project); generator.writeStringField("environment", this.environment); generator.writeStringField("serverName", this.serverName); generator.writeStringField("backtrace", ExceptionUtils.getStackTrace(throwable)); generator.writeStringField("message", rootThrowable.getMessage()); generator.writeStringField("logMessage", message); generator.writeStringField("type", rootThrowable.getClass().getName()); if (level != Level.ERROR) { generator.writeStringField("errorLevel", level.toString()); } writeContext(generator); generator.writeEndObject(); generator.close(); }
From source file:com.google.gerrit.pgm.util.SiteProgram.java
/** @return provides database connectivity and site path. */ protected Injector createDbInjector(final DataSourceProvider.Context context) { final File sitePath = getSitePath(); final List<Module> modules = new ArrayList<Module>(); Module sitePathModule = new AbstractModule() { @Override/*from w ww . ja va2 s. co m*/ protected void configure() { bind(File.class).annotatedWith(SitePath.class).toInstance(sitePath); } }; modules.add(sitePathModule); modules.add(new LifecycleModule() { @Override protected void configure() { bind(DataSourceProvider.Context.class).toInstance(context); bind(Key.get(DataSource.class, Names.named("ReviewDb"))) .toProvider(SiteLibraryBasedDataSourceProvider.class).in(SINGLETON); listener().to(SiteLibraryBasedDataSourceProvider.class); } }); Module configModule = new GerritServerConfigModule(); modules.add(configModule); Injector cfgInjector = Guice.createInjector(sitePathModule, configModule); Config cfg = cfgInjector.getInstance(Key.get(Config.class, GerritServerConfig.class)); String dbType = cfg.getString("database", null, "type"); final DataSourceType dst = Guice.createInjector(new DataSourceModule(), configModule, sitePathModule) .getInstance(Key.get(DataSourceType.class, Names.named(dbType.toLowerCase()))); modules.add(new AbstractModule() { @Override protected void configure() { bind(DataSourceType.class).toInstance(dst); } }); modules.add(new DatabaseModule()); modules.add(new SchemaModule()); modules.add(new LocalDiskRepositoryManager.Module()); try { return Guice.createInjector(PRODUCTION, modules); } catch (CreationException ce) { final Message first = ce.getErrorMessages().iterator().next(); Throwable why = first.getCause(); if (why instanceof SQLException) { throw die("Cannot connect to SQL database", why); } if (why instanceof OrmException && why.getCause() != null && "Unable to determine driver URL".equals(why.getMessage())) { why = why.getCause(); if (isCannotCreatePoolException(why)) { throw die("Cannot connect to SQL database", why.getCause()); } throw die("Cannot connect to SQL database", why); } final StringBuilder buf = new StringBuilder(); if (why != null) { buf.append(why.getMessage()); why = why.getCause(); } else { buf.append(first.getMessage()); } while (why != null) { buf.append("\n caused by "); buf.append(why.toString()); why = why.getCause(); } throw die(buf.toString(), new RuntimeException("DbInjector failed", ce)); } }
From source file:com.timeinc.seleniumite.junit.SimpleSeleniumBuilderTest.java
private Throwable unwrapWebDriverException(Throwable e) { Throwable rval = e;/*from w w w . j ava2s. co m*/ // The runtime exception wrapper doesn't help in this case, toss it if (RuntimeException.class.isAssignableFrom(e.getClass()) && e.getCause() != null && WebDriverException.class.isAssignableFrom(e.getCause().getClass())) { // Strip the wrapping RuntimeException in this case rval = e.getCause(); } return rval; }
From source file:com.qpark.eip.core.ToString.java
private static String getStackTrace(final Throwable t, final boolean isCause) { StringBuffer sb = new StringBuffer(1024); if (isCause) { sb.append("Caused by: "); }//from w ww .j av a 2 s . c o m sb.append(t.getClass().getName()).append(": ").append(t.getMessage()).append("\n"); StackTraceElement[] stack = t.getStackTrace(); int classNameLines = 0; int classNameLinesMax = 3; boolean printDots = false; boolean firstLine = true; for (StackTraceElement elem : stack) { if (firstLine || elem.getClassName().startsWith(CLASSNAME) && classNameLines <= classNameLinesMax) { sb.append("\tat ").append(elem.toString()).append("\n"); classNameLines++; firstLine = false; printDots = false; } else { if (!printDots) { sb.append("\tat ...\n"); printDots = true; } classNameLines = 0; } } Throwable cause = t.getCause(); if (cause != null) { sb.append(getStackTrace(cause, true)); } return sb.toString(); }
From source file:com.sunrun.crportal.util.CRPortalUtil.java
public static Throwable getRootException(Throwable exception) { if (exception.getCause() != null) { return getRootException(exception.getCause()); }//ww w.j av a2 s . c o m return exception; }
From source file:io.druid.metadata.SQLFirehoseDatabaseConnector.java
public final boolean isTransientException(Throwable e) { return e != null && (e instanceof RetryTransactionException || e instanceof SQLTransientException || e instanceof SQLRecoverableException || e instanceof UnableToObtainConnectionException || e instanceof UnableToExecuteStatementException || (e instanceof SQLException && isTransientException(e.getCause())) || (e instanceof DBIException && isTransientException(e.getCause()))); }