List of usage examples for com.google.common.base Throwables propagateIfPossible
public static void propagateIfPossible(@Nullable Throwable throwable)
From source file:com.google.devtools.build.lib.util.RuntimeUtils.java
/** * In tests, System.exit may be disabled. Thus, the main thread should call this method whenever * it is about to block on thread completion that might hang because of a failed halt below. */// w w w . ja v a2 s . co m public static void maybePropagateUnprocessedThrowableIfInTest() { Throwables.propagateIfPossible(unprocessedThrowableInTest); }
From source file:com.blackducksoftware.bdio.SimpleBase.java
/** * Applies a function that can potentially throw an {@code UncheckedExecutionException} (like a cache). *//* ww w .ja v a 2 s.c om*/ protected static <T> T apply(Function<String, T> converter, String fullyQualifiedName) { try { return converter.apply(fullyQualifiedName); } catch (UncheckedExecutionException e) { Throwables.propagateIfPossible(e.getCause()); throw e; } }
From source file:co.cask.cdap.security.impersonation.ImpersonationUtils.java
/** * Helper function, to unwrap any exceptions that were wrapped * by {@link UserGroupInformation#doAs(PrivilegedExceptionAction)} *//*from w ww . j a v a2 s. c om*/ public static <T> T doAs(UserGroupInformation ugi, final Callable<T> callable) throws Exception { try { return ugi.doAs(new PrivilegedExceptionAction<T>() { @Override public T run() throws Exception { return callable.call(); } }); } catch (UndeclaredThrowableException e) { // UserGroupInformation#doAs will wrap any checked exceptions, so unwrap and rethrow here Throwable wrappedException = e.getUndeclaredThrowable(); Throwables.propagateIfPossible(wrappedException); if (wrappedException instanceof Exception) { throw (Exception) wrappedException; } // since PrivilegedExceptionAction#run can only throw Exception (besides runtime exception), // this should never happen LOG.warn("Unexpected exception while executing callable as {}.", ugi.getUserName(), wrappedException); throw Throwables.propagate(wrappedException); } }
From source file:com.epam.reportportal.listeners.ListenersUtils.java
/** * Handle exceptions in the listeners. log error in case of * {@link ReportPortalException} or {@link RestEndpointIOException} or * propagates exception exactly as-is, if and only if it is an instance of * {@link RuntimeException} or {@link Error}. * /* w ww. jav a 2 s.c om*/ * @param exception * @param logger * @param message */ public static void handleException(Exception exception, Logger logger, String message) { if (ReportPortalException.class.isInstance(exception) || RestEndpointIOException.class.getClass().equals(exception.getClass())) { if (logger != null) { logger.error(message, exception); } else { System.out.println(exception.getMessage()); } } else { Throwables.propagateIfPossible(exception); } }
From source file:net.minecraftforge.fml.common.event.FMLPostInitializationEvent.java
public Object buildSoftDependProxy(String modId, String className) { if (Loader.isModLoaded(modId)) { try {/*from ww w .j a va 2 s .c o m*/ Class<?> clz = Class.forName(className, true, Loader.instance().getModClassLoader()); return clz.newInstance(); } catch (Exception e) { Throwables.propagateIfPossible(e); return null; } } return null; }
From source file:alluxio.AbstractResourceRule.java
/** * @return a Closeable resource that makes the modification of the resource on construction and * restore the rule to the previous value on close. *///w w w. j a v a2 s.co m public Closeable toResource() throws Exception { return new Closeable() { { try { before(); } catch (Throwable t) { Throwables.propagateIfPossible(t); throw new RuntimeException(t); } } @Override public void close() { after(); } }; }
From source file:com.nesscomputing.amqp.AmqpFactoryProvider.java
@Override public ConnectionFactory get() { final URI amqpUri = amqpConfig.getAmqpConnectionUrl(); try {/*from w ww . j a v a 2 s .com*/ final ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setUri(amqpUri); return connectionFactory; } catch (Exception e) { Throwables.propagateIfPossible(e); } return null; }
From source file:org.apache.rocketmq.console.util.JsonUtil.java
public static void writeValue(Writer writer, Object obj) { try {// w ww .jav a 2 s. co m objectMapper.writeValue(writer, obj); } catch (IOException e) { Throwables.propagateIfPossible(e); } }
From source file:alluxio.cli.fs.command.StartSyncCommand.java
@Override protected void runPlainPath(AlluxioURI path, CommandLine cl) { System.out.println("Starting a full sync of '" + path + "'. This may take a while ..."); try {/*from ww w .jav a2 s. c om*/ mFileSystem.startSync(path); } catch (Exception e) { Throwables.propagateIfPossible(e); System.out.println("Failed to start automatic syncing of '" + path + "'."); throw new RuntimeException(e); } System.out.println("Started automatic syncing of '" + path + "'."); }
From source file:io.macgyver.ldap.LdapServiceFactory.java
@Override public Object doCreateInstance(ServiceDefinition def) { try {//from w w w .j a va2s. c o m Properties props = def.getProperties(); LdapContextSource cs = new LdapContextSource(); org.springframework.beans.BeanWrapper gw = new BeanWrapperImpl(cs); assignProperties(cs, props, true); cs.afterPropertiesSet(); return cs; } catch (Exception e) { Throwables.propagateIfPossible(e); throw new MacGyverException(e); } }