Java Method .getGenericExceptionTypes ()
Syntax
Method.getGenericExceptionTypes() has the following syntax.
public Type [] getGenericExceptionTypes()
Example
In the following code shows how to use Method.getGenericExceptionTypes() method.
/* w ww .j a v a 2s . co m*/
import java.lang.reflect.Method;
import java.lang.reflect.Type;
class X {
public void objectMethod(String arg) throws Exception{
System.out.println("Instance method: " + arg);
}
public static void classMethod() {
System.out.println("Class method");
}
}
public class Main {
public static void main(String[] args) {
try {
Class<?> clazz = Class.forName("X");
X x = (X) clazz.newInstance();
Class[] argTypes = { String.class };
Method method = clazz.getMethod("objectMethod", argTypes);
Type[] exp = method.getGenericExceptionTypes();
for(Type anno:exp){
System.out.println(anno);
}
System.out.println();
} catch (Exception e) {
System.err.println(e);
}
}
}
The code above generates the following result.