List of usage examples for java.lang Throwable getCause
public synchronized Throwable getCause()
From source file:org.alfresco.extension.bulkfilesystemimport.webscripts.BulkFilesystemImportWebScript.java
private String renderExceptionStackAsText(final Throwable t) { StringBuffer result = new StringBuffer(); if (t != null) { String message = t.getMessage(); Throwable cause = t.getCause(); if (cause != null) { result.append(renderExceptionStackAsText(cause)); result.append("\nWrapped by:"); }//from ww w . j av a 2s . c o m if (message == null) { message = ""; } result.append("\n"); result.append(t.getClass().getName()); result.append(": "); result.append(message); result.append("\n"); result.append(renderStackTraceElements(t.getStackTrace())); } return (result.toString()); }
From source file:com.ettrema.ldap.LdapConnection.java
protected void handleRequest(final byte[] inbuf, final int offset) throws IOException { try {// w w w.j a va 2s .co m txManager.tx(new Runnable() { @Override public void run() { try { _handleRequest(inbuf, offset); } catch (IOException ex) { throw new RuntimeException(ex); } } }); } catch (Throwable e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } else { throw new RuntimeException(e); } } }
From source file:cat.ereza.customactivityoncrash.CustomActivityOnCrash.java
/** * INTERNAL method that checks if the stack trace that just crashed is conflictive. This is true in the following scenarios: * - The application has crashed while initializing (handleBindApplication is in the stack) * - The error activity has crashed (activityClass is in the stack) * * @param throwable The throwable from which the stack trace will be checked * @param activityClass The activity class to launch when the app crashes * @return true if this stack trace is conflictive and the activity must not be launched, false otherwise *///from w ww. j a v a 2s .c o m private static boolean isStackTraceLikelyConflictive(Throwable throwable, Class<? extends Activity> activityClass) { do { StackTraceElement[] stackTrace = throwable.getStackTrace(); for (StackTraceElement element : stackTrace) { if ((element.getClassName().equals("android.app.ActivityThread") && element.getMethodName().equals("handleBindApplication")) || element.getClassName().equals(activityClass.getName())) { return true; } } } while ((throwable = throwable.getCause()) != null); return false; }
From source file:be.wegenenverkeer.common.resteasy.exception.ExceptionUtil.java
/** * Construct instance which allows investigating the exception. * * @param originalException exception to investigate *///from ww w.j av a 2s. c om public ExceptionUtil(Throwable originalException) { this.originalException = originalException; isRetryable = false; isRecoverable = true; Throwable exc = originalException; Throwable lastCause = exc; StringBuilder concat = new StringBuilder(); if (exc instanceof InvocationTargetException && null != exc.getCause()) { exc = exc.getCause(); } for (Throwable c = exc; c != null; c = getCause(c)) { if (concat.length() > 0) { concat.append("; "); } concat.append(getMessage(c)); String cn = c.getClass().getName().toLowerCase(Locale.ENGLISH); String em = c.getMessage(); if (em == null) { em = ""; } em = em.toLowerCase(Locale.ENGLISH); if (c instanceof java.rmi.UnmarshalException || c instanceof InvalidClassException || c instanceof ClassNotFoundException || c instanceof LinkageError || c instanceof VirtualMachineError || c instanceof IllegalAccessException) { isRecoverable = false; } else { if (cn.contains("deadlock") || em.contains("deadlock") || cn.contains("staleobjectexception") || em.contains("staleobjectexception") || cn.contains("sockettimeoutexception") || em.contains("sockettimeoutexception") || cn.contains("communicationexception") || em.contains("communicationexception") || cn.contains("concurrentmodificationexception")) { isRetryable = true; } } } concatenatedMessage = concat.toString(); shortMessage = getMessage(lastCause); }
From source file:com.flexive.war.beans.admin.main.StructureImportBean.java
/** * Refactorisation of the groovy upload/*from w w w . ja va 2 s. c o m*/ * * @param code the script code * @return returns true if the import / running the script went ok */ private boolean groovyUpload(String code) { final String fileName = "importConsole.groovy"; long start = System.currentTimeMillis(); try { result = ScriptConsoleBean.runScript(code, fileName, false); return true; } 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()); return false; } finally { executionTime = System.currentTimeMillis() - start; } }
From source file:jj.webdriver.WebDriverRule.java
private boolean saveScreenshotIfFound(Throwable t) { boolean hasScreenshot = false; if (t.getCause() instanceof ScreenshotException) { try {/*from w w w . j ava2 s .c o m*/ hasScreenshot = true; String screenshotBase64 = ((ScreenshotException) t.getCause()).getBase64EncodedScreenshot(); byte[] screenshot = Base64.decodeBase64(screenshotBase64); Path screenshotFile = screenshotDir.resolve(makeScreenShotName("error-screenshot")); Files.write(screenshotFile, screenshot); logger.info("saved error state screenshot {}", screenshotFile); } catch (Exception ioe) { logger.error("couldn't save the error screenshot", ioe); } } return hasScreenshot; }
From source file:com.developmentsprint.spring.breaker.hystrix.HystrixCircuitManager.java
@Override public Object execute(final Invoker invoker) { CircuitBreakerAttribute attr = invoker.getCircuitBreakerAttribute(); String circuitBreakerName = determineCommandName(attr); String circuitBreakerGroup = determineGroupName(attr); String threadPoolName = determineThreadPoolName(attr); if (!CONFIGURED_BREAKERS.containsKey(circuitBreakerName)) { synchronized (circuitBreakerName) { if (!CONFIGURED_BREAKERS.containsKey(circuitBreakerName)) { for (Map.Entry<String, String> entry : attr.getProperties().entrySet()) { String commandKey = String.format(INSTANCE_COMMAND_PROP_KEY_FORMAT, circuitBreakerName, entry.getKey()); configuration.setProperty(commandKey, entry.getValue()); String threadPoolKey = String.format(INSTANCE_THREADPOOL_PROP_KEY_FORMAT, threadPoolName, entry.getKey()); configuration.setProperty(threadPoolKey, entry.getValue()); String collapserKey = String.format(INSTANCE_COLLAPSER_PROP_KEY_FORMAT, threadPoolName, entry.getKey()); configuration.setProperty(collapserKey, entry.getValue()); }/* www .ja va 2s . co m*/ CONFIGURED_BREAKERS.put(circuitBreakerName, Boolean.TRUE); } } } if (log.isDebugEnabled()) { StringBuilder builder = new StringBuilder(); Iterator<String> keyIterator = configuration.getKeys(); while (keyIterator.hasNext()) { String key = keyIterator.next(); builder.append(System.getProperty("line.separator")).append("\t").append(key).append(" : ") .append(configuration.getString(key)); } log.debug("Configured Hystrix Properties: {}", builder); } final HystrixFallback<?> fallback = determineFallback(attr); log.debug("Creating circuit breaker command '{}' around {}", circuitBreakerName, new Object() { public String toString() { return invoker.getMethod().toString(); } }); HystrixCommand.Setter setter = HystrixCommand.Setter .withGroupKey(HystrixCommandGroupKey.Factory.asKey(circuitBreakerGroup)) .andCommandKey(HystrixCommandKey.Factory.asKey(circuitBreakerName)) .andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(threadPoolName)); HystrixCommand<Object> command = new HystrixCommand<Object>(setter) { @Override protected Object run() throws Exception { try { return invoker.invoke(); } catch (Exception e) { if (e.getCause() != null && e.getCause() instanceof Exception) { e = ((Exception) e.getCause()); } throw e; } } @Override protected Object getFallback() { if (fallback == null || fallback instanceof FailFastFallback) { return super.getFallback(); } else if (fallback instanceof FailSilentFallback) { return null; } else { return fallback.fallback(); } } }; try { return command.execute(); } catch (HystrixRuntimeException e) { Throwable t = e.getCause(); if (t instanceof CircuitBreakerException) { throw (CircuitBreakerException) t.getCause(); } else if (t instanceof TimeoutException) { throw new CircuitTimeoutException(t.getMessage(), t); } else if (t instanceof RejectedExecutionException) { throw new CircuitOverloadException(t.getMessage(), t); } throw new CircuitBreakerException(t); } }
From source file:de.fhg.iais.asc.commons.exceptions.AscReportableErrorException.java
private String getAllErrorMessages(Throwable e, ArrayList<String> list) { if (e != null) { if (!Strings.isNullOrEmpty(e.getLocalizedMessage())) { String message = e.getLocalizedMessage().trim(); if (!list.contains(message)) { list.add(message);/*from w w w .j av a 2 s . co m*/ } } return getAllErrorMessages(e.getCause(), list); } else { return list.toString(); } }
From source file:de.hybris.platform.servicelayer.impex.ImportValidationModesTest.java
@Test public void shouldReachServiceLayerWhenRunningInNonLegacyMode() { final InputStream impexStream = givenImpexStream(); try {//from w w w . ja v a 2s . c o m importStream(impexStream, ENCODING.name(), "testImpex", false); } catch (final ImpExException expectedImpExException) { final Throwable expectedModelSavingException = Utilities.getRootCauseOfType(expectedImpExException, ModelSavingException.class); assertThat(expectedModelSavingException).isNotNull().isInstanceOf(ModelSavingException.class); assertThat(expectedModelSavingException.getCause()).isNotNull() .isInstanceOf(InterceptorException.class); return; } fail("Exception was expected."); }
From source file:de.tudarmstadt.lt.ltbot.text.JSoupTextExtractor.java
@Override public String getPlaintext(final String htmltext) { try {/*w ww .ja va 2s. c o m*/ // preserve newlines // html = html.replaceAll("(?i)<br[^>]*>", "br2nl"); // <br>s are often just inserted for style String hhtmltext = _end_prgrph_ptrn.matcher(htmltext).replaceAll("</p>br2nl"); hhtmltext = _nwln_ptrn.matcher(hhtmltext).replaceAll("br2nl"); Document soup = Jsoup.parse(hhtmltext); String plaintext = soup.text(); plaintext = _tmp_nwln_ptrn.matcher(plaintext).replaceAll("\n"); plaintext = _emptln_ptrn.matcher(plaintext.trim()).replaceAll(""); return plaintext; } catch (Throwable t) { for (int i = 1; t != null && i < 10; i++) { LOG.log(Level.SEVERE, String.format("Failed to get plaintext from while '%s' (%d %s:%s).", StringUtils.abbreviate(htmltext, 100), i, t.getClass().getName(), t.getMessage()), t); t = t.getCause(); } return "Failed to get plaintext content \n" + htmltext; } }