java.lang.reflect.Method.getExceptionTypes()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中java.lang.reflect.Method.getExceptionTypes()方法的一些代码示例,展示了Method.getExceptionTypes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Method.getExceptionTypes()方法的具体详情如下:
包路径:java.lang.reflect.Method
类名称:Method
方法名:getExceptionTypes

Method.getExceptionTypes介绍

[英]Returns an array of Class objects that represent the types of the exceptions declared to be thrown by the underlying method represented by this Method object. Returns an array of length 0 if the method declares no exceptions in its throws clause.
[中]返回类对象数组,这些类对象表示由该方法对象表示的基础方法引发的异常类型。如果方法在其throws子句中声明没有异常,则返回长度为0的数组。

代码示例

代码示例来源:origin: google/guava

private static boolean declaresInterruptedEx(Method method) {
 for (Class<?> exType : method.getExceptionTypes()) {
  // debate: == or isAssignableFrom?
  if (exType == InterruptedException.class) {
   return true;
  }
 }
 return false;
}

代码示例来源:origin: prestodb/presto

private static boolean declaresInterruptedEx(Method method) {
 for (Class<?> exType : method.getExceptionTypes()) {
  // debate: == or isAssignableFrom?
  if (exType == InterruptedException.class) {
   return true;
  }
 }
 return false;
}

代码示例来源:origin: org.mockito/mockito-core

public Class<?>[] getExceptionTypes() {
  return method.getExceptionTypes();
}

代码示例来源:origin: redisson/redisson

/**
 * {@inheritDoc}
 */
public int size() {
  return method.getExceptionTypes().length;
}

代码示例来源:origin: google/j2objc

private static boolean declaresInterruptedEx(Method method) {
 for (Class<?> exType : method.getExceptionTypes()) {
  // debate: == or isAssignableFrom?
  if (exType == InterruptedException.class) {
   return true;
  }
 }
 return false;
}

代码示例来源:origin: org.mockito/mockito-core

public boolean isValidException(Throwable throwable) {
  Class<?>[] exceptions = method.getExceptionTypes();
  Class<?> throwableClass = throwable.getClass();
  for (Class<?> exception : exceptions) {
    if (exception.isAssignableFrom(throwableClass)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Determine whether the given method explicitly declares the given
 * exception or one of its superclasses, which means that an exception
 * of that type can be propagated as-is within a reflective invocation.
 * @param method the declaring method
 * @param exceptionType the exception to throw
 * @return {@code true} if the exception can be thrown as-is;
 * {@code false} if it needs to be wrapped
 */
public static boolean declaresException(Method method, Class<?> exceptionType) {
  Assert.notNull(method, "Method must not be null");
  Class<?>[] declaredExceptions = method.getExceptionTypes();
  for (Class<?> declaredException : declaredExceptions) {
    if (declaredException.isAssignableFrom(exceptionType)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: google/j2objc

public boolean isValidException(Throwable throwable) {
  Class<?>[] exceptions = method.getExceptionTypes();
  Class<?> throwableClass = throwable.getClass();
  for (Class<?> exception : exceptions) {
    if (exception.isAssignableFrom(throwableClass)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public Class<?>[] getExceptionTypes() {
  return methodInvocation.getMethod().getExceptionTypes();
}

代码示例来源:origin: org.mockito/mockito-core

public SerializableMethod(Method method) {
  this.method = method;
  declaringClass = method.getDeclaringClass();
  methodName = method.getName();
  parameterTypes = SuspendMethod.trimSuspendParameterTypes(method.getParameterTypes());
  returnType = method.getReturnType();
  exceptionTypes = method.getExceptionTypes();
  isVarArgs = method.isVarArgs();
  isAbstract = (method.getModifiers() & Modifier.ABSTRACT) != 0;
}

代码示例来源:origin: google/j2objc

public SerializableMethod(Method method) {
  declaringClass = method.getDeclaringClass();
  methodName = method.getName();
  parameterTypes = method.getParameterTypes();
  returnType = method.getReturnType();
  exceptionTypes = method.getExceptionTypes();
  isVarArgs = method.isVarArgs();
}

代码示例来源:origin: redisson/redisson

/**
 * {@inheritDoc}
 */
public TypeDescription.Generic get(int index) {
  return new OfMethodExceptionTypes.TypeProjection(method, index, method.getExceptionTypes());
}

代码示例来源:origin: redisson/redisson

/**
 * {@inheritDoc}
 */
public TypeList asErasures() {
  return new TypeList.ForLoadedTypes(method.getExceptionTypes());
}

代码示例来源:origin: redisson/redisson

private static void setThrows(MethodInfo minfo, ConstPool cp, Method orig) {
  Class[] exceptions = orig.getExceptionTypes();
  setThrows(minfo, cp, exceptions);
}

代码示例来源:origin: google/guava

/** Determines whether the given method can throw InterruptedException. */
private static boolean isInterruptible(Method method) {
 return Arrays.asList(method.getExceptionTypes()).contains(InterruptedException.class);
}

代码示例来源:origin: spring-projects/spring-framework

public static Type[] getExceptionTypes(Member member) {
  if (member instanceof Method) {
    return TypeUtils.getTypes(((Method) member).getExceptionTypes());
  }
  else if (member instanceof Constructor) {
    return TypeUtils.getTypes(((Constructor) member).getExceptionTypes());
  }
  else {
    throw new IllegalArgumentException("Cannot get exception types of a field");
  }
}

代码示例来源:origin: redisson/redisson

/**
 * {@inheritDoc}
 */
public TypeList.Generic getExceptionTypes() {
  if (TypeDescription.AbstractBase.RAW_TYPES) {
    return new TypeList.Generic.ForLoadedTypes(method.getExceptionTypes());
  }
  return new TypeList.Generic.OfMethodExceptionTypes(method);
}

代码示例来源:origin: google/j2objc

public static Type[] getExceptionTypes(Member member) {
  if (member instanceof Method) {
    return TypeUtils.getTypes(((Method)member).getExceptionTypes());
  } else if (member instanceof Constructor) {
    return TypeUtils.getTypes(((Constructor)member).getExceptionTypes());
  } else {
    throw new IllegalArgumentException("Cannot get exception types of a field");
  }
}

代码示例来源:origin: org.springframework/spring-core

public static Type[] getExceptionTypes(Member member) {
  if (member instanceof Method) {
    return TypeUtils.getTypes(((Method) member).getExceptionTypes());
  }
  else if (member instanceof Constructor) {
    return TypeUtils.getTypes(((Constructor) member).getExceptionTypes());
  }
  else {
    throw new IllegalArgumentException("Cannot get exception types of a field");
  }
}

代码示例来源:origin: robolectric/robolectric

private BaseAdapter(
  org.objectweb.asm.commons.Method asmMethod, Method method) {
 this(
   method,
   asmMethod,
   ReflectorClassWriter.this.visitMethod(
     Opcodes.ACC_PUBLIC,
     asmMethod.getName(),
     asmMethod.getDescriptor(),
     null,
     ReflectorClassWriter.getInternalNames(method.getExceptionTypes())));
}

相关文章

微信公众号

最新文章

更多