Example usage for com.google.common.base Throwables propagateIfPossible

List of usage examples for com.google.common.base Throwables propagateIfPossible

Introduction

In this page you can find the example usage for com.google.common.base Throwables propagateIfPossible.

Prototype

public static <X extends Throwable> void propagateIfPossible(@Nullable Throwable throwable,
        Class<X> declaredType) throws X 

Source Link

Document

Propagates throwable exactly as-is, if and only if it is an instance of RuntimeException , Error , or declaredType .

Usage

From source file:org.opensingular.lib.commons.base.SingularUtil.java

public static RuntimeException propagate(Throwable throwable) {
    Throwables.propagateIfPossible(throwable, SingularException.class);
    throw SingularException.rethrow(throwable);
}

From source file:com.googlecode.wmbutil.NiceMbException.java

/**
 * Propagate MbException and MbBrokerException instances.
 *
 * @param t - Throwable to be thrown if possible
 * @throws MbException/*from   w  ww  .  ja  v  a  2s  .  c om*/
 */
public static void propagateIfPossible(@Nullable Throwable t) throws MbException {
    Throwables.propagateIfPossible(t, MbBrokerException.class);
    Throwables.propagateIfPossible(t, MbException.class);
}

From source file:org.glowroot.local.store.StatementCloser.java

RuntimeException rethrow(Throwable e) throws SQLException {
    thrown = e;/*from w  w w .  j a v a  2 s.c o m*/
    Throwables.propagateIfPossible(e, SQLException.class);
    throw new RuntimeException(e);
}

From source file:com.streamsets.datacollector.util.LambdaUtil.java

/**
 * Runs a Supplier within the context of a specified ClassLoader.
 *
 * @param classLoader the ClassLoader to run the Supplier.
 * @param supplier the Supplier to run within the context of a specified ClassLoader.
 *//*from   w w w .  j a v a 2 s  .  co m*/
public static <T, E1 extends Exception> T withClassLoader(ClassLoader classLoader, Class<E1> e1,
        ExceptionSupplier<T> supplier) throws E1 {
    try {
        return withClassLoaderInternal(classLoader, supplier);
    } catch (Exception e) {
        Throwables.propagateIfPossible(e, e1);
        Throwables.propagate(e);
    }

    return null;
}

From source file:org.inferred.internal.source.FilerUtils.java

/**
 * Writes {@code source} to the correct file for {@code classToWrite}.
 *
 * <p>This is complicated mainly by an EJC bug that returns the wrong object from
 * {@link Writer#append(CharSequence)}, plus how to handle any exception thrown from
 * {@link Writer#close()}.//w ww .j a va  2s.co  m
 */
public static void writeCompilationUnit(Filer filer, QualifiedName classToWrite, Element originatingElement,
        String source) throws IOException {
    Writer writer = filer.createSourceFile(classToWrite.toString(), originatingElement).openWriter();
    try {
        writer.append(source);
    } catch (Throwable e) {
        try {
            writer.close();
        } catch (Throwable t) {
            // Use suppressed exceptions in Java 7+
            if (ADD_SUPPRESSED != null) {
                try {
                    ADD_SUPPRESSED.invoke(e, t);
                } catch (Exception x) {
                    throw new RuntimeException("Failed to add suppressed exception: " + x.getMessage(), e);
                }
            }
            // Ignore any error thrown calling close() in Java 6
        }
        Throwables.propagateIfPossible(e, IOException.class);
        throw Throwables.propagate(e);
    }
    writer.close();
}

From source file:ru.runa.wfe.extension.orgfunction.GetActorsOrgFunctionBase.java

@Override
public final List<? extends Executor> getExecutors(Object... parameters) throws OrgFunctionException {
    try {/*from   w  ww  .jav  a  2  s. c o m*/
        List<Long> codes = getActorCodes(parameters);
        log.debug("Actor codes result: " + codes);
        return executorDao.getActorsByCodes(codes);
    } catch (Exception e) {
        Throwables.propagateIfPossible(e, OrgFunctionException.class);
        throw new OrgFunctionException(e);
    }
}

From source file:org.glowroot.local.store.StatementCloser.java

void close() throws SQLException {
    Throwable throwable = thrown;
    try {// w ww  . ja  v a 2s  .  c  o m
        statement.close();
    } catch (Throwable e) {
        if (throwable == null) {
            throwable = e;
        }
    }
    if (throwable != null) {
        Throwables.propagateIfPossible(throwable, SQLException.class);
        throw new AssertionError(throwable); // not possible
    }
}

From source file:org.glowroot.agent.fat.storage.util.ResultSetCloser.java

void close() throws SQLException {
    Throwable throwable = thrown;
    try {// w ww.j a v a  2  s  .  c om
        resultSet.close();
    } catch (Throwable e) {
        if (throwable == null) {
            throwable = e;
        }
    }
    if (throwable != null) {
        Throwables.propagateIfPossible(throwable, SQLException.class);
        throw new AssertionError(throwable); // not possible
    }
}

From source file:com.planet57.gshell.util.jline.LoggingCompleter.java

@Override
public void complete(final LineReader reader, final ParsedLine line, final List<Candidate> candidates) {
    log.trace("Complete: reader={}, line={}, candidates={}", reader, line, candidates);
    try {/*from  ww w . j  a  va  2s  .c o m*/
        delegate.complete(reader, line, candidates);
    } catch (Exception e) {
        // FIXME: this is required in part due to: https://github.com/jline/jline3/issues/115
        log.warn("Completer failed", e);
        Throwables.propagateIfPossible(e, RuntimeException.class);
        throw new RuntimeException(e);
    }
}

From source file:com.metamx.http.client.GoHandler.java

public <Intermediate, Final> ListenableFuture<Final> run(Request request,
        HttpResponseHandler<Intermediate, Final> handler, Duration requestReadTimeout) throws Exception {
    try {/*from   w w  w .j  a  v a2s.  com*/
        final ListenableFuture<Final> retVal = go(request, handler, requestReadTimeout);
        succeeded = true;
        return retVal;
    } catch (Throwable e) {
        succeeded = false;
        Throwables.propagateIfPossible(e, Exception.class);
        throw Throwables.propagate(e);
    }
}