本文整理了Java中java.lang.reflect.InvocationTargetException.getCause()
方法的一些代码示例,展示了InvocationTargetException.getCause()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。InvocationTargetException.getCause()
方法的具体详情如下:
包路径:java.lang.reflect.InvocationTargetException
类名称:InvocationTargetException
方法名:getCause
[英]Returns the cause of this exception, which may be null.
[中]返回此异常的原因,该异常可能为空。
代码示例来源:origin: google/guava
private Object invokeGeneratorMethod(Method generator, Object... args) {
try {
return generator.invoke(this, args);
} catch (InvocationTargetException e) {
throwIfUnchecked(e.getCause());
throw new RuntimeException(e.getCause());
} catch (Exception e) {
throwIfUnchecked(e);
throw new RuntimeException(e);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void addTransformer(ClassFileTransformer transformer) {
try {
this.addTransformerMethod.invoke(this.classLoader, transformer);
}
catch (InvocationTargetException ex) {
throw new IllegalStateException("GlassFish addTransformer method threw exception", ex.getCause());
}
catch (Throwable ex) {
throw new IllegalStateException("Could not invoke GlassFish addTransformer method", ex);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void addTransformer(ClassFileTransformer transformer) {
try {
this.addTransformerMethod.invoke(this.classLoader, transformer);
}
catch (InvocationTargetException ex) {
throw new IllegalStateException("Tomcat addTransformer method threw exception", ex.getCause());
}
catch (Throwable ex) {
throw new IllegalStateException("Could not invoke Tomcat addTransformer method", ex);
}
}
代码示例来源:origin: google/guava
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
Method typeVariableMethod = typeVariableMethods.get(methodName);
if (typeVariableMethod == null) {
throw new UnsupportedOperationException(methodName);
} else {
try {
return typeVariableMethod.invoke(typeVariableImpl, args);
} catch (InvocationTargetException e) {
throw e.getCause();
}
}
}
}
代码示例来源:origin: spring-projects/spring-framework
public ClassLoader getThrowawayClassLoader() {
try {
Object classFinder = this.getClassFinderMethod.invoke(this.classLoader);
Object parent = this.getParentMethod.invoke(this.classLoader);
// arguments for 'clone'-like method
return (ClassLoader) this.wlGenericClassLoaderConstructor.newInstance(classFinder, parent);
}
catch (InvocationTargetException ex) {
throw new IllegalStateException("WebLogic GenericClassLoader constructor failed", ex.getCause());
}
catch (Throwable ex) {
throw new IllegalStateException("Could not construct WebLogic GenericClassLoader", ex);
}
}
代码示例来源:origin: google/guava
@GwtIncompatible // java.lang.reflect
private static Object invokeAccessibleNonThrowingMethod(
Method method, Object receiver, Object... params) {
try {
return method.invoke(receiver, params);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw propagate(e.getCause());
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public ClassLoader getThrowawayClassLoader() {
try {
return new OverridingClassLoader(this.classLoader, (ClassLoader) this.copyMethod.invoke(this.classLoader));
}
catch (InvocationTargetException ex) {
throw new IllegalStateException("GlassFish copy method threw exception", ex.getCause());
}
catch (Throwable ex) {
throw new IllegalStateException("Could not invoke GlassFish copy method", ex);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public ClassLoader getThrowawayClassLoader() {
try {
return new OverridingClassLoader(this.classLoader, (ClassLoader) this.copyMethod.invoke(this.classLoader));
}
catch (InvocationTargetException ex) {
throw new IllegalStateException("Tomcat copy method threw exception", ex.getCause());
}
catch (Throwable ex) {
throw new IllegalStateException("Could not invoke Tomcat copy method", ex);
}
}
代码示例来源:origin: spring-projects/spring-framework
private Throwable getTestResultException(ITestResult testResult) {
Throwable testResultException = testResult.getThrowable();
if (testResultException instanceof InvocationTargetException) {
testResultException = ((InvocationTargetException) testResultException).getCause();
}
return testResultException;
}
代码示例来源:origin: greenrobot/EventBus
void invokeSubscriber(Subscription subscription, Object event) {
try {
subscription.subscriberMethod.method.invoke(subscription.subscriber, event);
} catch (InvocationTargetException e) {
handleSubscriberException(subscription, event, e.getCause());
} catch (IllegalAccessException e) {
throw new IllegalStateException("Unexpected exception", e);
}
}
代码示例来源:origin: spring-projects/spring-framework
public void addTransformer(ClassFileTransformer transformer) {
Assert.notNull(transformer, "ClassFileTransformer must not be null");
try {
InvocationHandler adapter = new WebSphereClassPreDefinePlugin(transformer);
Object adapterInstance = Proxy.newProxyInstance(this.wsPreProcessorClass.getClassLoader(),
new Class<?>[] {this.wsPreProcessorClass}, adapter);
this.addPreDefinePlugin.invoke(this.classLoader, adapterInstance);
}
catch (InvocationTargetException ex) {
throw new IllegalStateException("WebSphere addPreDefinePlugin method threw exception", ex.getCause());
}
catch (Throwable ex) {
throw new IllegalStateException("Could not invoke WebSphere addPreDefinePlugin method", ex);
}
}
代码示例来源:origin: spring-projects/spring-framework
public ClassLoader getThrowawayClassLoader() {
try {
ClassLoader loader = this.cloneConstructor.newInstance(getClassLoader());
// Clear out the transformers (copied as well)
List<?> list = (List<?>) this.transformerList.get(loader);
list.clear();
return loader;
}
catch (InvocationTargetException ex) {
throw new IllegalStateException("WebSphere CompoundClassLoader constructor failed", ex.getCause());
}
catch (Throwable ex) {
throw new IllegalStateException("Could not construct WebSphere CompoundClassLoader", ex);
}
}
代码示例来源:origin: spring-projects/spring-framework
public void addTransformer(ClassFileTransformer transformer) {
Assert.notNull(transformer, "ClassFileTransformer must not be null");
try {
InvocationHandler adapter = new WebLogicClassPreProcessorAdapter(transformer, this.classLoader);
Object adapterInstance = Proxy.newProxyInstance(this.wlPreProcessorClass.getClassLoader(),
new Class<?>[] {this.wlPreProcessorClass}, adapter);
this.addPreProcessorMethod.invoke(this.classLoader, adapterInstance);
}
catch (InvocationTargetException ex) {
throw new IllegalStateException("WebLogic addInstanceClassPreProcessor method threw exception", ex.getCause());
}
catch (Throwable ex) {
throw new IllegalStateException("Could not invoke WebLogic addInstanceClassPreProcessor method", ex);
}
}
代码示例来源:origin: google/guava
@Override
public void run() {
try {
invokeSubscriberMethod(event);
} catch (InvocationTargetException e) {
bus.handleSubscriberException(e.getCause(), context(event));
}
}
});
代码示例来源:origin: org.mockito/mockito-core
private static Object tryInvoke(Method origin, Object instance, Object[] arguments) throws Throwable {
try {
return origin.invoke(instance, arguments);
} catch (InvocationTargetException exception) {
Throwable cause = exception.getCause();
new ConditionalStackTraceFilter().filter(hideRecursiveCall(cause, new Throwable().getStackTrace().length, origin.getDeclaringClass()));
throw cause;
}
}
代码示例来源:origin: google/guava
private Object invokeListMethod(Method method, Object[] args) throws Throwable {
try {
Object returnValue = method.invoke(delegate, args);
mutateDelegate();
return returnValue;
} catch (InvocationTargetException e) {
throw e.getCause();
} catch (IllegalAccessException e) {
throw new AssertionError(e);
}
}
代码示例来源:origin: skylot/jadx
private void rethrow(String msg, InvocationTargetException ie) {
Throwable cause = ie.getCause();
if (cause instanceof AssertionError) {
System.err.println(msg);
throw (AssertionError) cause;
} else {
cause.printStackTrace();
fail(msg + cause.getMessage());
}
}
代码示例来源:origin: google/guava
@GwtIncompatible("Reflection")
public void testAllOverloads_checkNotNull() throws Exception {
for (ImmutableList<Class<?>> sig : allSignatures(Object.class)) {
Method checkArgumentMethod =
Preconditions.class.getMethod("checkNotNull", sig.toArray(new Class<?>[] {}));
checkArgumentMethod.invoke(
null /* static method */, getParametersForSignature(new Object(), sig));
Object[] failingParams = getParametersForSignature(null, sig);
try {
checkArgumentMethod.invoke(null /* static method */, failingParams);
fail();
} catch (InvocationTargetException ite) {
assertFailureCause(ite.getCause(), NullPointerException.class, failingParams);
}
}
}
代码示例来源:origin: google/guava
@GwtIncompatible("Reflection")
public void testAllOverloads_checkArgument() throws Exception {
for (ImmutableList<Class<?>> sig : allSignatures(boolean.class)) {
Method checkArgumentMethod =
Preconditions.class.getMethod("checkArgument", sig.toArray(new Class<?>[] {}));
checkArgumentMethod.invoke(null /* static method */, getParametersForSignature(true, sig));
Object[] failingParams = getParametersForSignature(false, sig);
try {
checkArgumentMethod.invoke(null /* static method */, failingParams);
fail();
} catch (InvocationTargetException ite) {
assertFailureCause(ite.getCause(), IllegalArgumentException.class, failingParams);
}
}
}
代码示例来源:origin: google/guava
@GwtIncompatible("Reflection")
public void testAllOverloads_checkState() throws Exception {
for (ImmutableList<Class<?>> sig : allSignatures(boolean.class)) {
Method checkArgumentMethod =
Preconditions.class.getMethod("checkState", sig.toArray(new Class<?>[] {}));
checkArgumentMethod.invoke(null /* static method */, getParametersForSignature(true, sig));
Object[] failingParams = getParametersForSignature(false, sig);
try {
checkArgumentMethod.invoke(null /* static method */, failingParams);
fail();
} catch (InvocationTargetException ite) {
assertFailureCause(ite.getCause(), IllegalStateException.class, failingParams);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!