package com.logicbig.example.method;
import java.lang.reflect.Method;
import java.util.Arrays;
public class GetExceptionTypesExample {
public static void main(String... args) throws NoSuchMethodException {
Method m = GetExceptionTypesExample.class.getDeclaredMethod("main", String[].class);
Class<?>[] c = m.getExceptionTypes();
System.out.println(Arrays.toString(c));
}
}
Output
[class java.lang.NoSuchMethodException]
package com.logicbig.example.method;
import java.io.IOException;
import java.lang.reflect.Method;
import java.text.ParseException;
import java.util.Arrays;
public class GetExceptionTypesExample2 {
private static class Processor {
private void process() throws IOException, ParseException {}
}
public static void main(String... args) throws NoSuchMethodException {
Method m = Processor.class.getDeclaredMethod("process");
Class<?>[] exceptionTypes = m.getExceptionTypes();
System.out.println(Arrays.toString(exceptionTypes));
}
}
Output
[class java.io.IOException, class java.text.ParseException]