/** * Note: always throws the failure in some form. The return value is to keep the compiler happy. */ public static RuntimeException throwAsUncheckedException(Throwable t) { return throwAsUncheckedException(t, false); }
@Override public void run() { try { //some code that throws checked exception } catch(Exception e) { throw new UncheckedException(e); } }
public void setValue(Object target, Object value) { try { method.invoke(target, value); } catch (InvocationTargetException e) { throw UncheckedException.unwrapAndRethrow(e); } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } } }
protected void dispatch(MethodInvocation invocation, Dispatch<MethodInvocation> handler) { try { handler.dispatch(invocation); } catch (UncheckedException e) { throw new ListenerNotificationException(invocation, getErrorMessage(), Collections.singletonList(e.getCause())); } catch (RuntimeException t) { throw t; } catch (Throwable t) { throw new ListenerNotificationException(invocation, getErrorMessage(), Collections.singletonList(t)); } }
protected void dispatch(MethodInvocation invocation, Dispatch<MethodInvocation> handler) { try { handler.dispatch(invocation); } catch (UncheckedException e) { throw new ListenerNotificationException(invocation, getErrorMessage(), Collections.singletonList(e.getCause())); } catch (RuntimeException t) { throw t; } catch (Throwable t) { throw new ListenerNotificationException(invocation, getErrorMessage(), Collections.singletonList(t)); } }
/** * Note: always throws the failure in some form. The return value is to keep the compiler happy. */ public static RuntimeException throwAsUncheckedException(Throwable t) { return throwAsUncheckedException(t, false); }
public void setValue(Object target, Object value) { try { method.invoke(target, value); } catch (InvocationTargetException e) { throw UncheckedException.unwrapAndRethrow(e); } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } } }
@Override public T getOrNull() { try { return value.call(); } catch (Exception e) { throw new UncheckedException(e); } } }
public String toString() { if (toStringRuntimeEx != null) { throw UncheckedException.throwAsUncheckedException(toStringRuntimeEx); } return toString; } }
public F getValue(T target) { try { return returnType.cast(method.invoke(target)); } catch (InvocationTargetException e) { throw UncheckedException.unwrapAndRethrow(e); } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } } }
@Override public void visitClassPath(URL[] classPath) { for (URL url : classPath) { try { implementationClassPath.add(new File(toURI(url))); } catch (URISyntaxException e) { throw new UncheckedException(e); } } } }.visit(classLoader);
public void rethrowFailure() { if (failure == null) { return; } throw UncheckedException.throwAsUncheckedException(failure); }
public F getValue(T target) { try { return returnType.cast(method.invoke(target)); } catch (InvocationTargetException e) { throw UncheckedException.unwrapAndRethrow(e); } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } } }
@Override public void visitClassPath(URL[] classPath) { for (URL url : classPath) { try { implementationClassPath.add(new File(toURI(url))); } catch (URISyntaxException e) { throw new UncheckedException(e); } } } }.visit(classLoader);
private Object getAnnotationParameterValue(Annotation annotation, Method method) { try { return method.invoke(annotation); } catch (IllegalAccessException e) { throw UncheckedException.throwAsUncheckedException(e); } catch (InvocationTargetException e) { throw UncheckedException.throwAsUncheckedException(e); } }
public static boolean hasDefaultToString(Object object) { try { return object.getClass().getMethod("toString").getDeclaringClass() == Object.class; } catch (java.lang.NoSuchMethodException e) { throw new UncheckedException(e); } }
public boolean awaitNextResult() { try { if (next == null) { next = received.take(); } } catch (InterruptedException e) { throw UncheckedException.throwAsUncheckedException(e); } return next != END; }
public static boolean hasDefaultToString(Object object) { try { return object.getClass().getMethod("toString").getDeclaringClass() == Object.class; } catch (java.lang.NoSuchMethodException e) { throw new UncheckedException(e); } }
public void stop() { try { closeable.close(); } catch (IOException e) { throw UncheckedException.throwAsUncheckedException(e); } } };
private static URI toURI(URL url) throws URISyntaxException { try { return url.toURI(); } catch (URISyntaxException e) { try { return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile().replace(" ", "%20")).toURI(); } catch (MalformedURLException e1) { throw new UncheckedException(e1); } } } }