List of usage examples for java.lang Throwable getCause
public synchronized Throwable getCause()
From source file:com.amalto.core.save.RecordValidationTest.java
protected static Throwable getRootException(Throwable e) { Throwable root = e; while (root != null && root.getCause() != null && root.getCause().getMessage() != null) { root = root.getCause();/* w ww . j a v a 2s.com*/ } return root; }
From source file:com.mpower.clientcollection.utilities.WebUtils.java
/** * Common method for returning a parsed xml document given a url and the * http context and client objects involved in the web connection. * * @param urlString// w w w . j a va 2s .c om * @param localContext * @param httpclient * @return */ public static DocumentFetchResult getXmlDocument(String urlString, HttpContext localContext, HttpClient httpclient) { URI u = null; try { URL url = new URL(urlString); u = url.toURI(); } catch (Exception e) { e.printStackTrace(); return new DocumentFetchResult(e.getLocalizedMessage() // + app.getString(R.string.while_accessing) + urlString); + ("while accessing") + urlString, 0); } if (u.getHost() == null) { return new DocumentFetchResult("Invalid server URL (no hostname): " + urlString, 0); } // if https then enable preemptive basic auth... if (u.getScheme().equals("https")) { enablePreemptiveBasicAuth(localContext, u.getHost()); } // set up request... HttpGet req = WebUtils.createOpenRosaHttpGet(u); //req.addHeader(WebUtils.ACCEPT_ENCODING_HEADER, WebUtils.GZIP_CONTENT_ENCODING); HttpResponse response = null; try { response = httpclient.execute(req, localContext); int statusCode = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); if (statusCode != HttpStatus.SC_OK) { WebUtils.discardEntityBytes(response); if (statusCode == HttpStatus.SC_UNAUTHORIZED) { // clear the cookies -- should not be necessary? ClientCollection.getInstance().getCookieStore().clear(); } String webError = response.getStatusLine().getReasonPhrase() + " (" + statusCode + ")"; return new DocumentFetchResult(u.toString() + " responded with: " + webError, statusCode); } if (entity == null) { String error = "No entity body returned from: " + u.toString(); Log.e(t, error); return new DocumentFetchResult(error, 0); } if (!entity.getContentType().getValue().toLowerCase(Locale.ENGLISH) .contains(WebUtils.HTTP_CONTENT_TYPE_TEXT_XML)) { WebUtils.discardEntityBytes(response); String error = "ContentType: " + entity.getContentType().getValue() + " returned from: " + u.toString() + " is not text/xml. This is often caused a network proxy. Do you need to login to your network?"; Log.e(t, error); return new DocumentFetchResult(error, 0); } // parse response Document doc = null; try { InputStream is = null; InputStreamReader isr = null; try { is = entity.getContent(); Header contentEncoding = entity.getContentEncoding(); if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase(WebUtils.GZIP_CONTENT_ENCODING)) { is = new GZIPInputStream(is); } isr = new InputStreamReader(is, "UTF-8"); doc = new Document(); KXmlParser parser = new KXmlParser(); parser.setInput(isr); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); doc.parse(parser); isr.close(); isr = null; } finally { if (isr != null) { try { // ensure stream is consumed... final long count = 1024L; while (isr.skip(count) == count) ; } catch (Exception e) { // no-op } try { isr.close(); } catch (Exception e) { // no-op } } if (is != null) { try { is.close(); } catch (Exception e) { // no-op } } } } catch (Exception e) { e.printStackTrace(); String error = "Parsing failed with " + e.getMessage() + "while accessing " + u.toString(); Log.e(t, error); return new DocumentFetchResult(error, 0); } boolean isOR = false; Header[] fields = response.getHeaders(WebUtils.OPEN_ROSA_VERSION_HEADER); if (fields != null && fields.length >= 1) { isOR = true; boolean versionMatch = false; boolean first = true; StringBuilder b = new StringBuilder(); for (Header h : fields) { if (WebUtils.OPEN_ROSA_VERSION.equals(h.getValue())) { versionMatch = true; break; } if (!first) { b.append("; "); } first = false; b.append(h.getValue()); } if (!versionMatch) { Log.w(t, WebUtils.OPEN_ROSA_VERSION_HEADER + " unrecognized version(s): " + b.toString()); } } return new DocumentFetchResult(doc, isOR); } catch (Exception e) { clearHttpConnectionManager(); e.printStackTrace(); String cause; Throwable c = e; while (c.getCause() != null) { c = c.getCause(); } cause = c.toString(); String error = "Error: " + cause + " while accessing " + u.toString(); Log.w(t, error); return new DocumentFetchResult(error, 0); } }
From source file:edu.uci.ics.asterix.result.ResultUtils.java
/** * Extract the meaningful part of a stack trace: * a. the causes in the stack trace hierarchy * b. the top exception for each cause// w ww . j a v a 2 s . co m * * @param e * @return the contacted message containing a and b. */ private static String extractErrorSummary(Throwable e) { StringBuilder errorMessageBuilder = new StringBuilder(); Throwable cause = e; errorMessageBuilder.append(cause.getLocalizedMessage()); while (cause != null) { StackTraceElement[] stackTraceElements = cause.getStackTrace(); errorMessageBuilder .append(stackTraceElements.length > 0 ? "\n caused by: " + stackTraceElements[0] : ""); cause = cause.getCause(); } return errorMessageBuilder.toString(); }
From source file:com.aptana.core.epl.downloader.RepositoryStatusHelper.java
@SuppressWarnings("rawtypes") public static Throwable unwind(Throwable t) { for (;;) {//from w w w. j av a2 s . c om Class tc = t.getClass(); // We don't use instanceof operator since we want // the explicit class, not subclasses. // if (tc != RuntimeException.class && tc != InvocationTargetException.class && tc != IOException.class) break; Throwable cause = t.getCause(); if (cause == null) break; String msg = t.getMessage(); if (msg != null && !msg.equals(cause.toString())) break; t = cause; } return t; }
From source file:com.clank.launcher.swing.SwingHelper.java
public static void addErrorDialogCallback(final Window owner, ListenableFuture<?> future) { Futures.addCallback(future, new FutureCallback<Object>() { @Override//from w ww . ja v a 2 s . co m public void onSuccess(Object result) { } @Override public void onFailure(Throwable t) { if (t instanceof InterruptedException || t instanceof CancellationException) { return; } String message; if (t instanceof LauncherException) { message = t.getLocalizedMessage(); t = t.getCause(); } else { message = t.getLocalizedMessage(); if (message == null) { message = _("errors.genericError"); } } log.log(Level.WARNING, "Task failed", t); SwingHelper.showErrorDialog(owner, message, _("errorTitle"), t); } }, SwingExecutor.INSTANCE); }
From source file:com.aptana.core.epl.downloader.RepositoryStatusHelper.java
private static void deeplyPrint(Throwable t, PrintStream strm, boolean stackTrace, int level) { if (t instanceof CoreException) deeplyPrint((CoreException) t, strm, stackTrace, level); else {/* w w w.java 2 s . c o m*/ appendLevelString(strm, level); if (stackTrace) t.printStackTrace(strm); else { strm.println(t.toString()); Throwable cause = t.getCause(); if (cause != null) { strm.print("Caused by: "); //$NON-NLS-1$ deeplyPrint(cause, strm, stackTrace, level); } } } }
From source file:com.ichi2.anki.AnkiDroidApp.java
private static String getExceptionHash(Throwable th) { final StringBuilder res = new StringBuilder(); Throwable cause = th; while (cause != null) { final StackTraceElement[] stackTraceElements = cause.getStackTrace(); for (final StackTraceElement e : stackTraceElements) { res.append(e.getClassName()); res.append(e.getMethodName()); }/* ww w.ja va 2s.co m*/ cause = cause.getCause(); } return Integer.toHexString(res.toString().hashCode()); }
From source file:de.tudarmstadt.lt.ltbot.postprocessor.DecesiveValueProducerPerplexity.java
static void addExtraInfo(CrawlURI uri, String key, Object value) { try {/* w w w. j a v a 2 s .com*/ uri.getExtraInfo().put(key, value); uri.getData().put(key, value); } catch (Throwable t) { for (int i = 1; t != null && i < 10; i++) { LOG.log(Level.WARNING, String.format("Failed to add perplexity value to extra info for uri: '%s' (%d-%s:%s).", uri.toString(), i, t.getClass().getName(), t.getMessage())); t = t.getCause(); } } }
From source file:edu.temple.cis3238.wiki.utils.StringUtils.java
/** * * @param e/*from w w w .ja v a 2 s .c om*/ * @return */ public static final String stackStraceAsStringDetails(final Throwable e) { StringBuilder sb = new StringBuilder(""); if (e != null) { final StringWriter stringWriter = new StringWriter(); try { e.printStackTrace(new PrintWriter(stringWriter)); sb.append(stringWriter.toString()); sb.append("\nCause:"); sb.append(e); Throwable t = e.getCause(); while (t != null) { sb.append(t); sb.append("\n"); t = t.getCause(); } } catch (Exception exc) { sb.append(e.getMessage()); } finally { return StringUtils.toS(sb.toString(), "Sorry.. full stack trace not available"); } } else { LOG.warning("Exception null printing stack track"); return "Null exception"; } }
From source file:org.eclipse.cft.server.core.internal.CloudErrorUtil.java
protected static HttpClientErrorException getHttpClientError(Throwable t) { if (t == null) { return null; }// w w w . jav a 2s . c o m HttpClientErrorException httpException = null; if (t instanceof HttpClientErrorException) { httpException = (HttpClientErrorException) t; } else { Throwable cause = t.getCause(); if (cause instanceof HttpClientErrorException) { httpException = (HttpClientErrorException) cause; } } return httpException; }