List of usage examples for java.lang Throwable getCause
public synchronized Throwable getCause()
From source file:Main.java
/** * From the given throwable or its cause, or cause's cause, etc., * get the first one that has a non-empty message, and return that message. * * @param t//from www. jav a 2s .c o m * @return the first non-empty message string, or null. */ public static String getFirstMeaningfulMessage(Throwable t) { if (t == null) return null; String m = t.getMessage(); if (m != null && !m.isEmpty()) { return m; } return getFirstMeaningfulMessage(t.getCause()); }
From source file:it.tidalwave.northernwind.frontend.ui.component.sitemap.DefaultSitemapViewController.java
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Nonnull/*from ww w . j av a2 s. c o m*/ private static Throwable rootCause(final @Nonnull Throwable t) { final Throwable cause = t.getCause(); return (cause != null) ? rootCause(cause) : t; }
From source file:ExceptionUtils.java
/** * Locates a particular type of exception, working its way via the cause property of each exception in the exception * stack.// ww w .j a va 2s. c om * * @param t the outermost exception * @param type the type of exception to search for * @return the first exception of the given type, if found, or null */ public static <T extends Throwable> T findCause(Throwable t, Class<T> type) { Throwable current = t; while (current != null) { if (type.isInstance(current)) return type.cast(current); // Not a match, work down. current = current.getCause(); } return null; }
From source file:com.myee.tarot.core.exception.ExceptionHelper.java
public static <G extends Throwable, J extends RuntimeException> void processException(Class<G> refineType, Class<J> wrapType, String message, Throwable e) throws G { if (refineType.isAssignableFrom(e.getClass())) { throw (G) e; }//from w w w . j av a 2 s . co m if (e.getCause() != null) { processException(refineType, wrapType, message, e.getCause()); } if (e instanceof UndeclaredThrowableException) { processException(refineType, wrapType, message, ((UndeclaredThrowableException) e).getUndeclaredThrowable()); } if (e instanceof InvocationTargetException) { processException(refineType, wrapType, message, ((InvocationTargetException) e).getTargetException()); } throw wrapException(e, wrapType, message); }
From source file:org.addhen.birudo.data.net.BaseHttpClient.java
public static Throwable getRootCause(Throwable throwable) { if (throwable.getCause() != null) { return getRootCause(throwable.getCause()); }//from w w w . j a va 2s .c o m return throwable; }
From source file:io.servicecomb.foundation.vertx.VertxUtils.java
private static <T> void complete(AsyncResultCallback<T> callback, T result, Throwable e) { if (e != null) { callback.fail(e.getCause()); return;//from w ww .j a v a 2s . c o m } callback.success(result); }
From source file:com.opengamma.language.connector.Main.java
/** * Entry point from the service wrapper - starts the service. * // w w w .j a v a 2s .c o m * @return null if the service started properly, otherwise a string for display to the user describing why the stack wasn't started */ public static String svcStart() { try { s_logger.info("Starting OpenGamma language integration service"); s_springContext = new LanguageSpringContext(); return null; } catch (final BeanCreationException e) { s_logger.error("Exception thrown", e); Throwable t = e; do { t = t.getCause(); } while (t instanceof BeanCreationException); if (t != null) { return t.getMessage(); } else { return e.getMessage(); } } catch (final Throwable t) { s_logger.error("Exception thrown", t); return t.getMessage(); } }
From source file:com.opengamma.engine.depgraph.ExceptionWrapper.java
/** * Create a new wrapper instance and add it to the canonical map. * /* w ww. j av a 2s . c om*/ * @param exception exception to wrap * @param canon the canonical map to add to */ public static ExceptionWrapper createAndPut(final Throwable exception, final Map<ExceptionWrapper, ExceptionWrapper> canon) { final ExceptionWrapper instance; final Throwable cause = exception.getCause(); if (cause != null) { instance = new ExceptionWrapper(exception, createAndPut(cause, canon)); } else { instance = new ExceptionWrapper(exception, null); } final ExceptionWrapper existing = canon.get(instance); if (existing != null) { existing.incrementCount(); return existing; } else { canon.put(instance, instance); return instance; } }
From source file:com.myee.tarot.core.exception.ExceptionHelper.java
public static <G extends Throwable, J extends RuntimeException> RuntimeException refineException( Class<G> refineType, Class<J> wrapType, String message, Throwable e) { if (refineType.isAssignableFrom(e.getClass())) { return wrapException(e, wrapType, message); }//from w ww. j a va2s .c om if (e.getCause() != null) { return refineException(refineType, wrapType, message, e.getCause()); } if (e instanceof UndeclaredThrowableException) { return refineException(refineType, wrapType, message, ((UndeclaredThrowableException) e).getUndeclaredThrowable()); } if (e instanceof InvocationTargetException) { return refineException(refineType, wrapType, message, ((InvocationTargetException) e).getTargetException()); } return wrapException(e, wrapType, message); }
From source file:com.qwazr.utils.http.HttpResponseEntityException.java
public static HttpResponseEntityException findFirstCause(Throwable e) { if (e == null) return null; if (e instanceof HttpResponseEntityException) return (HttpResponseEntityException) e; return findFirstCause(e.getCause()); }