本文整理汇总了Java中java.lang.reflect.InvocationTargetException.getCause方法的典型用法代码示例。如果您正苦于以下问题:Java InvocationTargetException.getCause方法的具体用法?Java InvocationTargetException.getCause怎么用?Java InvocationTargetException.getCause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.InvocationTargetException
的用法示例。
在下文中一共展示了InvocationTargetException.getCause方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setDeclaredPropertyTest
import java.lang.reflect.InvocationTargetException; //导入方法依赖的package包/类
public void setDeclaredPropertyTest(Map<String, Object> config, String schemaLocation, String typeName, Class<?> fieldType, String fieldName, String fieldGetter, Object value) throws Throwable {
ClassLoader resultsClassLoader = schemaRule.generateAndCompile(schemaLocation, "com.example", config);
Class<?> type = resultsClassLoader.loadClass("com.example." + typeName);
Object instance = type.newInstance();
try {
type.getMethod("set", String.class, Object.class)
.invoke(instance, fieldName, value);
} catch (InvocationTargetException e) {
throw e.getCause();
}
assertThat("set for field " + fieldName + " of type " + fieldType + " works.",
fieldType.cast(type.getMethod(fieldGetter)
.invoke(instance)),
equalTo(value));
}
示例2: runTests
import java.lang.reflect.InvocationTargetException; //导入方法依赖的package包/类
@Override
public void runTests() throws Exception {
for (Method m : getClass().getDeclaredMethods()) {
Annotation a = m.getAnnotation(Test.class);
if (a != null) {
for (FrameKind fk : FrameKind.values()) {
for (OverviewKind ok : OverviewKind.values()) {
for (HtmlKind hk : HtmlKind.values()) {
try {
out.println("Running test " + m.getName() + " " + fk + " " + ok + " " + hk);
Path base = Paths.get(m.getName() + "_" + fk + "_" + ok + "_" + hk);
Files.createDirectories(base);
m.invoke(this, new Object[]{base, fk, ok, hk});
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
throw (cause instanceof Exception) ? ((Exception) cause) : e;
}
out.println();
}
}
}
}
}
printSummary();
}
示例3: run
import java.lang.reflect.InvocationTargetException; //导入方法依赖的package包/类
/** Run all test cases. */
void run() throws Exception {
try {
initTestClasses();
for (Method m: getClass().getDeclaredMethods()) {
Annotation a = m.getAnnotation(Test.class);
if (a != null) {
System.err.println(m.getName());
try {
m.invoke(this, new Object[] { });
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
throw (cause instanceof Exception) ? ((Exception) cause) : e;
}
System.err.println();
}
}
if (errors > 0)
throw new Exception(errors + " errors occurred");
} finally {
fm.close();
}
}
示例4: invoke
import java.lang.reflect.InvocationTargetException; //导入方法依赖的package包/类
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
if (method.getName().equals("setAutoCommit")) {
setAutoCommit(((Boolean)args[0]).booleanValue());
} else if (method.getName().equals("setTransactionIsolation")) {
setTransactionIsolation(((Integer)args[0]).intValue());
} else if (method.getName().equals("close")) {
close();
} else {
try {
return method.invoke(conn, args);
}
catch(InvocationTargetException ite) {
throw (ite.getCause() != null ? ite.getCause() : ite);
}
}
return null;
}
示例5: throwRuntimeException
import java.lang.reflect.InvocationTargetException; //导入方法依赖的package包/类
/**
* Throw a {@link RuntimeException} with given message and cause lifted from an {@link
* InvocationTargetException}. If the specified {@link InvocationTargetException} does not have a
* cause, neither will the {@link RuntimeException}.
*/
private static void throwRuntimeException(String msg, InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause != null) {
throw new RuntimeException(msg + ": " + cause.getMessage(), cause);
} else {
throw new RuntimeException(msg + ": " + e.getMessage(), e);
}
}
示例6: provision
import java.lang.reflect.InvocationTargetException; //导入方法依赖的package包/类
/** Provisions a new T. */
private T provision(Errors errors, InternalContext context,
ConstructionContext<T> constructionContext) throws ErrorsException {
try {
T t;
try {
Object[] parameters = SingleParameterInjector.getAll(errors, context, parameterInjectors);
t = constructionProxy.newInstance(parameters);
constructionContext.setProxyDelegates(t);
} finally {
constructionContext.finishConstruction();
}
// Store reference. If an injector re-enters this factory, they'll get the same reference.
constructionContext.setCurrentReference(t);
membersInjector.injectMembers(t, errors, context, false);
membersInjector.notifyListeners(t, errors);
return t;
} catch (InvocationTargetException userException) {
Throwable cause = userException.getCause() != null
? userException.getCause()
: userException;
throw errors.withSource(constructionProxy.getInjectionPoint())
.errorInjectingConstructor(cause).toException();
} finally {
constructionContext.removeCurrentReference();
}
}
示例7: testInvokeAfterAppDelete
import java.lang.reflect.InvocationTargetException; //导入方法依赖的package包/类
@Test
public void testInvokeAfterAppDelete() throws Exception {
FirebaseApp app = FirebaseApp.initializeApp(firebaseOptions, "testInvokeAfterAppDelete");
FirebaseAuth auth = FirebaseAuth.getInstance(app);
assertNotNull(auth);
app.delete();
for (Method method : auth.getClass().getDeclaredMethods()) {
int modifiers = method.getModifiers();
if (!Modifier.isPublic(modifiers) || Modifier.isStatic(modifiers)) {
continue;
}
List<Object> parameters = new ArrayList<>(method.getParameterTypes().length);
for (Class<?> parameterType : method.getParameterTypes()) {
parameters.add(Defaults.defaultValue(parameterType));
}
try {
method.invoke(auth, parameters.toArray());
fail("No error thrown when invoking auth after deleting app; method: " + method.getName());
} catch (InvocationTargetException expected) {
String message = "FirebaseAuth instance is no longer alive. This happens when "
+ "the parent FirebaseApp instance has been deleted.";
Throwable cause = expected.getCause();
assertTrue(cause instanceof IllegalStateException);
assertEquals(message, cause.getMessage());
}
}
}
示例8: callWithException
import java.lang.reflect.InvocationTargetException; //导入方法依赖的package包/类
public T callWithException(Object receiver, Object... args) throws Throwable {
try {
return (T) this.method.invoke(receiver, args);
} catch (InvocationTargetException e) {
if (e.getCause() != null) {
throw e.getCause();
}
throw e;
}
}
示例9: invoke
import java.lang.reflect.InvocationTargetException; //导入方法依赖的package包/类
private static Object invoke(Method m, Object obj, Object... args) throws Throwable {
try {
return m.invoke(obj, args);
} catch (InvocationTargetException e) {
throw e.getCause();
}
}
示例10: colToChar_wrongArguments_throwsException
import java.lang.reflect.InvocationTargetException; //导入方法依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void colToChar_wrongArguments_throwsException() throws Throwable {
Method method = MoveTranslator.class.getDeclaredMethod("colToChar", int.class);
method.setAccessible(true);
try {
method.invoke(null, 8);
} catch (InvocationTargetException e) {
throw e.getCause();
}
}
示例11: invoke
import java.lang.reflect.InvocationTargetException; //导入方法依赖的package包/类
private Object invoke(Object proxy, Method method, Object[] args, boolean retry) throws Throwable // NOSONAR
{
String methodName = method.getName();
Method pMethod = iface.getClass().getMethod(methodName, method.getParameterTypes());
try
{
return pMethod.invoke(iface, args);
}
catch( InvocationTargetException e )
{
throw e.getCause();
}
}
示例12: call
import java.lang.reflect.InvocationTargetException; //导入方法依赖的package包/类
@Override
public Bundle call(Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
String methodName = (String) args[args.length - 3];
String arg = (String) args[args.length - 2];
int methodType = getMethodType(methodName);
if (METHOD_GET == methodType) {
String presetValue = PRE_SET_VALUES.get(arg);
if (presetValue != null) {
Bundle res = new Bundle();
res.putString("value", presetValue);
return res;
}
}
if (METHOD_PUT == methodType) {
if (isSecureMethod(methodName)) {
return null;
}
}
try {
return super.call(method, args);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof SecurityException) {
return null;
}
throw e;
}
}
示例13: constructor_nullOffset
import java.lang.reflect.InvocationTargetException; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void constructor_nullOffset() throws Throwable {
Constructor<OffsetTime> con = OffsetTime.class.getDeclaredConstructor(LocalTime.class, ZoneOffset.class);
con.setAccessible(true);
try {
con.newInstance(LocalTime.of(11, 30, 0, 0), null);
} catch (InvocationTargetException ex) {
throw ex.getCause();
}
}
示例14: testURLClassLoader
import java.lang.reflect.InvocationTargetException; //导入方法依赖的package包/类
public static void testURLClassLoader(String loaderName) throws Exception {
System.err.println("---- test URLClassLoader name: " + loaderName);
URL[] urls = new URL[] { CLASSES_DIR.toUri().toURL() };
ClassLoader parent = ClassLoader.getSystemClassLoader();
URLClassLoader loader = new URLClassLoader(loaderName, urls, parent);
Class<?> c = Class.forName(THROW_EXCEPTION_CLASS, true, loader);
Method method = c.getMethod("throwError");
try {
// invoke p.ThrowException::throwError
method.invoke(null);
} catch (InvocationTargetException x) {
Throwable e = x.getCause();
e.printStackTrace();
StackTraceElement[] stes = e.getStackTrace();
StackWalker.StackFrame[] frames = new StackWalker.StackFrame[] {
Utils.makeStackFrame(c, "throwError", "ThrowException.java"),
Utils.makeStackFrame(WithClassLoaderName.class, "testURLClassLoader",
SRC_FILENAME),
Utils.makeStackFrame(WithClassLoaderName.class, "main", SRC_FILENAME),
};
// p.ThrowException.throwError
Utils.checkFrame(loaderName, frames[0], stes[0]);
// skip reflection frames
int i = 1;
while (i < stes.length) {
String cn = stes[i].getClassName();
if (!cn.startsWith("java.lang.reflect.") &&
!cn.startsWith("jdk.internal.reflect."))
break;
i++;
}
// WithClassLoaderName.testURLClassLoader
Utils.checkFrame("app", frames[1], stes[i]);
// WithClassLoaderName.main
Utils.checkFrame("app", frames[2], stes[i+1]);
}
}
示例15: onHandleError
import java.lang.reflect.InvocationTargetException; //导入方法依赖的package包/类
private Object onHandleError(InvocationTargetException e) throws Throwable {
if (e.getCause() instanceof SecurityException) {
return 0;
}
throw e.getCause();
}