НЕ понимаю почему не выбрасывает исключения
package com.javarush.task.task36.task3602;
import javafx.print.Collation;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/*
Найти класс по описанию Ӏ Java Collections: 6 уровень, 6 лекция
*/
public class Solution {
public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException {
System.out.println(getExpectedClass());
}
public static Class getExpectedClass() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
Class[] classes = Collection.class.getDeclaredClasses();
for (Class clazz: classes){
if (List.class.isAssignableFrom(clazz) &&
Modifier.isPrivate(clazz.getModifiers()) &&
Modifier.isStatic(clazz.getModifiers())) {
try {
Constructor constructor = clazz.getDeclaredConstructor();
Method method = clazz.getDeclaredMethod("get", int.class);
method.setAccessible(true);
method.invoke(constructor.newInstance(),0);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
if (e.getCause().toString().contains("IndexOutOfBoundsException"))
return clazz;
} catch (InstantiationException e) {
e.printStackTrace();
}
}
}
return null;
}
}