private static Semaphore onInterruption(final InterruptedException e) { Thread.interrupted(); throw ExceptionUtils.throwAsRuntimeException(e); } }
private void invalidOperation() throws NoSuchFieldException { try { getClass().getDeclaredField("virtualField"); } catch (NoSuchFieldException e) { ExceptionUtils.changeAndThrowException(e, FIELD_DOES_NOT_EXIST); } } }
public static void changeAndThrowException(Throwable throwable, String customMessage) { Throwable newThrowable = createNewException(throwable, customMessage); //Attention: helper which allows to use a trick to throw a cached checked exception without a wrapping exception new ExceptionHelper<RuntimeException>().throwException(newThrowable); }
ExceptionUtils.throwAsRuntimeException(e.getCause()); ExceptionUtils.changeAndThrowException(e, customMessage);
ExceptionUtils.throwAsRuntimeException(e.getCause()); ExceptionUtils.changeAndThrowException(e, customMessage);
private static Object uncheckedInvoke(Method method, Object target, Object... args) { try { return method.invoke(target, args); } catch (IllegalAccessException e) { throw ExceptionUtils.throwAsRuntimeException(e); } catch (InvocationTargetException e) { throw ExceptionUtils.throwAsRuntimeException(e.getCause()); } }
ExceptionUtils.throwAsRuntimeException(e.getCause()); ExceptionUtils.changeAndThrowException(e, customMessage);
@Test public void rethrowUncheckedException() { try { ExceptionUtils.changeAndThrowException(new ClassCastException(), "custom"); } catch (ClassCastException e) { Assert.assertEquals("custom", e.getMessage()); Assert.assertEquals(null, e.getCause()); return; } Assert.fail(); }
public static void changeAndThrowException(Throwable throwable, String customMessage) { Throwable newThrowable = createNewException(throwable, customMessage); //Attention: helper which allows to use a trick to throw a cached checked exception without a wrapping exception new ExceptionHelper<RuntimeException>().throwException(newThrowable); }
protected boolean isValidPath(ServletContextEvent sce, ConfigDescriptor configDescriptor) { try { return sce.getServletContext().getResource(configDescriptor.getPath()) != null; } catch (MalformedURLException e) { throw ExceptionUtils.throwAsRuntimeException(e); } }
@Test public void changeMessageOfCustomException() { try { ExceptionUtils.changeAndThrowException( new CustomException("old", new Exception("original")), "new"); } catch (RuntimeException e) { Assert.fail(); } catch (Exception e) { Assert.assertEquals("original", e.getCause().getMessage()); Assert.assertEquals("new", e.getMessage()); Assert.assertEquals(CustomException.class, e.getClass()); return; } Assert.fail(); }
public static void changeAndThrowException(Throwable throwable, String customMessage) { Throwable newThrowable = createNewException(throwable, customMessage); //Attention: helper which allows to use a trick to throw a cached checked exception without a wrapping exception new ExceptionHelper<RuntimeException>().throwException(newThrowable); }
protected boolean isValidPath(ServletContextEvent sce, ConfigDescriptor configDescriptor) { try { return sce.getServletContext().getResource(configDescriptor.getPath()) != null; } catch (MalformedURLException e) { throw ExceptionUtils.throwAsRuntimeException(e); } }
@Test public void changeMessageOfInvalidCustomException() { try { ExceptionUtils.changeAndThrowException( new IncompatibleCustomException("old", new Exception("original"), 1), "new"); } catch (RuntimeException e) { Assert.fail(); } catch (Exception e) { Assert.assertEquals("original", e.getCause().getMessage()); Assert.assertEquals("old", e.getMessage()); Assert.assertEquals(IncompatibleCustomException.class, e.getClass()); Assert.assertEquals(1, ((IncompatibleCustomException) e).getCustomParameter()); return; } Assert.fail(); }
@Override public boolean getRollbackOnly() { try { return getTransactionStatus() == Status.STATUS_MARKED_ROLLBACK; } catch (SystemException e) { throw ExceptionUtils.throwAsRuntimeException(e); } }
private NavigationHandler wrapNavigationHandlerWithNewWrapper(NavigationHandler handler) { if (ConfigurableNavigationHandler.class.isAssignableFrom(handler.getClass())) { try { Constructor deltaSpikeNavigationHandlerWrapperConstructor = this.navigationHandlerWrapperClass.getConstructor(ConfigurableNavigationHandler.class); NavigationHandler navigationHandlerWrapper = (NavigationHandler)deltaSpikeNavigationHandlerWrapperConstructor.newInstance(handler); return navigationHandlerWrapper; } catch (Exception e) { throw ExceptionUtils.throwAsRuntimeException(e); } } return null; }
@Override public boolean getRollbackOnly() { try { return getTransactionStatus() == Status.STATUS_MARKED_ROLLBACK; } catch (SystemException e) { throw ExceptionUtils.throwAsRuntimeException(e); } }
private void invokeMethod(Object target) { try { this.method.invokeExplosively(target); } catch (Throwable throwable) { throw ExceptionUtils.throwAsRuntimeException(throwable); } } }
private NavigationHandler wrapNavigationHandlerWithNewWrapper(NavigationHandler handler) { if (ConfigurableNavigationHandler.class.isAssignableFrom(handler.getClass())) { try { Constructor deltaSpikeNavigationHandlerWrapperConstructor = this.navigationHandlerWrapperClass.getConstructor(ConfigurableNavigationHandler.class); NavigationHandler navigationHandlerWrapper = (NavigationHandler)deltaSpikeNavigationHandlerWrapperConstructor.newInstance(handler); return navigationHandlerWrapper; } catch (Exception e) { throw ExceptionUtils.throwAsRuntimeException(e); } } return null; }
@Override public Object proceed() throws Exception { try { return process(proxy, method, args, repositoryMetadata, repositoryMethodMetadata); } catch (Throwable t) { throw ExceptionUtils.throwAsRuntimeException(t); } } });