use of java.lang.reflect.UndeclaredThrowableException in project robovm by robovm.
the class WTInvocationHandler method main.
public static void main(String[] args) {
WTMix mix = new WTMix();
InvocationHandler handler = new WTInvocationHandler(mix);
Object proxy;
try {
proxy = Proxy.newProxyInstance(WrappedThrow.class.getClassLoader(), new Class[] { InterfaceW1.class, InterfaceW2.class }, handler);
} catch (IllegalArgumentException iae) {
System.out.println("WT init failed");
return;
}
InterfaceW1 if1 = (InterfaceW1) proxy;
InterfaceW2 if2 = (InterfaceW2) proxy;
try {
if1.throwFunky();
System.err.println("No exception thrown");
} catch (UndeclaredThrowableException ute) {
System.out.println("Got expected UTE");
} catch (Throwable t) {
System.err.println("Got unexpected exception: " + t);
}
try {
if1.throwFunky2();
System.err.println("No exception thrown");
} catch (IOException ioe) {
System.out.println("Got expected IOE");
} catch (Throwable t) {
System.err.println("Got unexpected exception: " + t);
}
try {
if2.throwFunky2();
System.err.println("No exception thrown");
} catch (IOException ioe) {
System.out.println("Got expected IOE");
} catch (Throwable t) {
System.err.println("Got unexpected exception: " + t);
}
/*
* Throw exceptions, walking down the hierarchy.
*/
try {
if1.throwException();
System.err.println("No exception thrown");
} catch (UndeclaredThrowableException ute) {
System.out.println("Got expected UTE");
} catch (Throwable t) {
System.err.println("Got unexpected exception: " + t);
}
try {
if1.throwBase();
System.err.println("No exception thrown");
} catch (UndeclaredThrowableException ute) {
System.out.println("Got expected UTE");
} catch (Throwable t) {
System.err.println("Got unexpected exception: " + t);
}
try {
if2.throwSub();
System.err.println("No exception thrown");
} catch (SubException se) {
System.out.println("Got expected exception");
} catch (Throwable t) {
System.err.println("Got unexpected exception: " + t);
}
try {
if2.throwSubSub();
System.err.println("No exception thrown");
} catch (SubException se) {
System.out.println("Got expected exception");
} catch (Throwable t) {
System.err.println("Got unexpected exception: " + t);
}
/*
* Make sure that, if the class explicitly allows the base
* class of an exception, that we still allow it.
*/
try {
if1.bothThrowBase();
System.err.println("No exception thrown");
} catch (BaseException se) {
System.out.println("Got expected exception");
} catch (Throwable t) {
System.err.println("Got unexpected exception: " + t);
}
}
use of java.lang.reflect.UndeclaredThrowableException in project spring-framework by spring-projects.
the class ApplicationListenerMethodAdapter method doInvoke.
/**
* Invoke the event listener method with the given argument values.
*/
protected Object doInvoke(Object... args) {
Object bean = getTargetBean();
ReflectionUtils.makeAccessible(this.bridgedMethod);
try {
return this.bridgedMethod.invoke(bean, args);
} catch (IllegalArgumentException ex) {
assertTargetBean(this.bridgedMethod, bean, args);
throw new IllegalStateException(getInvocationErrorMessage(bean, ex.getMessage(), args), ex);
} catch (IllegalAccessException ex) {
throw new IllegalStateException(getInvocationErrorMessage(bean, ex.getMessage(), args), ex);
} catch (InvocationTargetException ex) {
// Throw underlying exception
Throwable targetException = ex.getTargetException();
if (targetException instanceof RuntimeException) {
throw (RuntimeException) targetException;
} else {
String msg = getInvocationErrorMessage(bean, "Failed to invoke event listener method", args);
throw new UndeclaredThrowableException(targetException, msg);
}
}
}
use of java.lang.reflect.UndeclaredThrowableException in project spring-framework by spring-projects.
the class ScheduledMethodRunnable method run.
@Override
public void run() {
try {
ReflectionUtils.makeAccessible(this.method);
this.method.invoke(this.target);
} catch (InvocationTargetException ex) {
ReflectionUtils.rethrowRuntimeException(ex.getTargetException());
} catch (IllegalAccessException ex) {
throw new UndeclaredThrowableException(ex);
}
}
use of java.lang.reflect.UndeclaredThrowableException in project spring-framework by spring-projects.
the class AbstractAopProxyTests method testUndeclaredCheckedException.
/**
* An interceptor throws a checked exception not on the method signature.
* For efficiency, we don't bother unifying java.lang.reflect and
* org.springframework.cglib UndeclaredThrowableException
*/
@Test
public void testUndeclaredCheckedException() throws Throwable {
final Exception unexpectedException = new Exception();
// Test return value
MethodInterceptor mi = new MethodInterceptor() {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
throw unexpectedException;
}
};
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
pc.addAdvice(mi);
// We don't care about the object
pc.setTarget(new TestBean());
AopProxy aop = createAopProxy(pc);
ITestBean tb = (ITestBean) aop.getProxy();
try {
// Note: exception param below isn't used
tb.getAge();
fail("Should have wrapped exception raised by interceptor");
} catch (UndeclaredThrowableException thrown) {
assertEquals("exception matches", unexpectedException, thrown.getUndeclaredThrowable());
} catch (Exception ex) {
ex.printStackTrace();
fail("Didn't expect exception: " + ex);
}
}
use of java.lang.reflect.UndeclaredThrowableException in project jstorm by alibaba.
the class JstormMaster method publishContainerStartEvent.
private static void publishContainerStartEvent(final TimelineClient timelineClient, Container container, String domainId, UserGroupInformation ugi) {
final TimelineEntity entity = new TimelineEntity();
entity.setEntityId(container.getId().toString());
entity.setEntityType(DSEntity.DS_CONTAINER.toString());
entity.setDomainId(domainId);
entity.addPrimaryFilter(JOYConstants.USER, ugi.getShortUserName());
TimelineEvent event = new TimelineEvent();
event.setTimestamp(System.currentTimeMillis());
event.setEventType(DSEvent.DS_CONTAINER_START.toString());
event.addEventInfo(JOYConstants.NODE, container.getNodeId().toString());
event.addEventInfo(JOYConstants.RESOURCES, container.getResource().toString());
entity.addEvent(event);
try {
ugi.doAs(new PrivilegedExceptionAction<TimelinePutResponse>() {
@Override
public TimelinePutResponse run() throws Exception {
return timelineClient.putEntities(entity);
}
});
} catch (Exception e) {
LOG.error("Container start event could not be published for " + container.getId().toString(), e instanceof UndeclaredThrowableException ? e.getCause() : e);
}
}
Aggregations