public PropagatedRuntimeException(String message, Throwable cause, boolean causeEmbeddedInMessage) { super(message, cause); warnIfWrapping(cause); this.causeEmbeddedInMessage = causeEmbeddedInMessage; }
/** True if the given exception is skippable in any of the supplied contexts. */ public static boolean isSkippableInContext(Throwable e, Object... contexts) { if (!(e instanceof CanSkipInContext)) return false; for (Object c: contexts) { if (((CanSkipInContext)e).canSkipInContext(c)) { return true; } } return false; }
public void handleException(Throwable throwable) throws Exception { Exceptions.propagateIfFatal(throwable); if (throwable instanceof Exception) { // allow checked exceptions to be passed through throw (Exception)throwable; } throw Exceptions.propagate(throwable); }
/** As {@link #propagate(String, Throwable)} but unlike earlier deprecated version * this always re-wraps including the given message, until semantics of that method change to match this. * See {@link #propagateAnnotateIfWrapping(String, Throwable)} if the message * should be omitted and the given throwable preserved if it can already be propagated. */ public static RuntimeException propagateAnnotated(String msg, Throwable throwable) { return propagate(msg, throwable, true); }
@SuppressWarnings({ "unchecked", "rawtypes" }) protected <D extends EntityDriver> ReferenceWithError<Class<? extends D>> loadClass(String className, ClassLoader classLoader) { try { return (ReferenceWithError) ReferenceWithError.newInstanceWithoutError((Class<? extends EntityDriver>)classLoader.loadClass(className)); } catch (Exception e) { Exceptions.propagateIfFatal(e); return ReferenceWithError.newInstanceThrowingError(null, e); } } }
@Override public <D extends EntityDriver> ReferenceWithError<Class<? extends D>> resolve(DriverDependentEntity<D> entity, Class<D> driverInterface, Location location) { try { String newName = inferDriverClassName(entity, driverInterface, location); if (newName==null) return null; return loadDriverClass(newName, entity, driverInterface); } catch (Exception e) { Exceptions.propagateIfFatal(e); return ReferenceWithError.newInstanceThrowingError(null, e); } }
/** * If machine is restarting, then will get WinRM IOExceptions */ protected Throwable findExceptionCausedByWindowsRestart(Exception e) { return Exceptions.getFirstThrowableOfType(e, WebServiceException.class) != null ? Exceptions.getFirstThrowableOfType(e, WebServiceException.class/*Wraps Soap exceptions*/) : Exceptions.getFirstThrowableOfType(e, Fault.class/*Wraps IO exceptions*/); }
@Override public String toString() { if (causeEmbeddedInMessage) { return super.toString(); } else { return Exceptions.appendSeparator(super.toString(), Exceptions.collapseText(getCause())); } }
/** like {@link #collapse(Throwable)} but returning a one-line message suitable for logging without traces */ public static String collapseText(Throwable t) { return collapseText(t, false); }
/** creates the given exception, but without propagating it, for use when caller will be wrapping */ public static Throwable create(Iterable<? extends Throwable> exceptions) { return create(null, exceptions); } /** creates the given exception, but without propagating it, for use when caller will be wrapping */
/** creates (but does not throw) a new {@link PropagatedRuntimeException} whose * message and cause are taken from the first _interesting_ element in the source */ public static Throwable collapse(Throwable source) { return collapse(source, true); }
/** * Propagate exceptions which are fatal. * <p> * Propagates only those exceptions which one rarely (if ever) wants to capture, * such as {@link InterruptedException} and {@link Error}s. */ public static void propagateIfFatal(Throwable throwable) { propagateIfInterrupt(throwable); if (throwable instanceof Error) { throw (Error) throwable; } }
/** throws error, even if there is one (even if masked), else returns the object */ public T getWithError() { checkNoError(); return object; }
@Override public boolean apply(Throwable input) { return input != null && isFatal(input); } }
/** * See {@link #propagate(Throwable)}. * <p> * The given message is included <b>only</b> if the given {@link Throwable} * needs to be wrapped; otherwise the message is not used. * To always include the message, use {@link #propagateAnnotated(String, Throwable)}. */ public static RuntimeException propagateAnnotateIfWrapping(String msg, Throwable throwable) { return propagate(msg, throwable, false); }
@Override public boolean apply(Throwable input) { return Exceptions.getFirstThrowableOfType(input, AllowedException.class) != null; } };
@Override public String get() { return Exceptions.collapseText(cause); } public Throwable getOriginal() { return cause; }
public PropagatedRuntimeException(Throwable cause) { super("" /* do not use default message as that destroys the toString */, cause); warnIfWrapping(cause); causeEmbeddedInMessage = false; }