/** * Used for synchronous execution of command. * * @return R * Result of {@link #run()} execution or a fallback from {@link #getFallback()} if the command fails for any reason. * @throws HystrixRuntimeException * if a failure occurs and a fallback cannot be retrieved * @throws HystrixBadRequestException * if invalid arguments or state were used representing a user failure, not a system failure * @throws IllegalStateException * if invoked more than once */ public R execute() { try { return queue().get(); } catch (Exception e) { throw Exceptions.sneakyThrow(decomposeException(e)); } }
/** * Throws the argument, return-type is RuntimeException so the caller can use a throw statement break out of the method */ public static RuntimeException sneakyThrow(Throwable t) { return Exceptions.<RuntimeException>doThrow(t); }
throw Exceptions.sneakyThrow(t);
/** * Throws the argument, return-type is RuntimeException so the caller can use a throw statement break out of the method */ public static RuntimeException sneakyThrow(Throwable t) { return Exceptions.<RuntimeException>doThrow(t); }
@Test public void testCastOfException(){ Exception exception = new IOException("simulated checked exception message"); try{ Exceptions.sneakyThrow(exception); fail(); } catch(Exception e){ assertTrue(e instanceof IOException); } } }
/** * Used for synchronous execution of command. * * @return R * Result of {@link #run()} execution or a fallback from {@link #getFallback()} if the command fails for any reason. * @throws HystrixRuntimeException * if a failure occurs and a fallback cannot be retrieved * @throws HystrixBadRequestException * if invalid arguments or state were used representing a user failure, not a system failure * @throws IllegalStateException * if invoked more than once */ public R execute() { try { return queue().get(); } catch (Exception e) { throw Exceptions.sneakyThrow(decomposeException(e)); } }
throw Exceptions.sneakyThrow(t);