Валидатор выдает ошибку, хотя по идее он должен все скомпилировать и обработать исключения. Вот например отрывок
try {
Ultimate ultimate = new Ultimate();
} catch (TypeNotPresentException vsevolod) {
exceptions.add(vsevolod);
}
Тут происходит попытка создать переменную неопределенного типа, так как класс Ultimate не определен, что ведет к ошибке и выбросу исключения и ниже в блоке catch его обработке, однако валидатор просто выдает ошибку в строке Ultimate ultimate = new Ultimate(); и все.
Или вот еще блок, тут должно быть выкинуто и обработано исключение, однако программа просто аварийно завершается
try {
String str[] = new String[15];
str[1] = 123;
} catch (ArrayStoreException stored) {
exceptions.add(stored);
}
Вот весь код:
import java.util.ArrayList;
import java.util.List;
/*
Нашествие исключений
*/
public class Solution {
public static List<Exception> exceptions = new ArrayList<Exception>();
public static void main(String[] args) {
initExceptions();
for (Exception exception : exceptions) {
System.out.println(exception);
}
}
private static void initExceptions() { //it's first exception
try {
float i = 1 / 0;
} catch (Exception e) {
exceptions.add(e);
}
try {
int[] array = new int[15];
array[17] = 45;
System.out.print("Эта строчка никогда не будет выведена!");
array[3] = 45;
} catch (ArrayIndexOutOfBoundsException e) {
exceptions.add(e);
}
try {
String a = "123";
if (!(a.equals("qwer"))) {
throw new MyException();
}
} catch (MyException e) {
//e.printStackTrace();
exceptions.add(e);
}
try {
int[] arrayMin = new int[-4];
} catch (NegativeArraySizeException q) {
exceptions.add(q);
}
try {
Ultimate ultimate = new Ultimate();
} catch (TypeNotPresentException vsevolod) {
exceptions.add(vsevolod);
}
try {
String str[] = new String[15];
str[1] = 123;
} catch (ArrayStoreException stored) {
exceptions.add(stored);
}
try {
String str = "qwer";
Integer a = (Integer) str;
} catch (ClassCastException classed) {
exceptions.add(classed);
}
try {
String asd = 123 + 45;
} catch (Exception iDontKnow) {
exceptions.add(iDontKnow);
}
try {
Abstract asd = new Abstract();
} catch (InstantiationException zxc) {
exceptions.add(zxc);
}
try {
Solution.field = 123;
} catch (NoSuchFieldException e) {
exceptions.add(e);
}
}
public static class MyException extends Exception {
public MyException() {
super.getMessage();
System.out.print("Это мое исключение!");
}
}
abstract class Abstract {
}
}package com.javarush.task.task14.task1419;
import java.util.ArrayList;
import java.util.List;
/*
Нашествие исключений
*/
public class Solution {
public static List<Exception> exceptions = new ArrayList<Exception>();
public static void main(String[] args) {
initExceptions();
for (Exception exception : exceptions) {
System.out.println(exception);
}
}
private static void initExceptions() { //it's first exception
try {
float i = 1 / 0;
} catch (Exception e) {
exceptions.add(e);
}
try {
int[] array = new int[15];
array[17] = 45;
System.out.print("Эта строчка никогда не будет выведена!");
array[3] = 45;
} catch (ArrayIndexOutOfBoundsException e) {
exceptions.add(e);
}
try {
String a = "123";
if (!(a.equals("qwer"))) {
throw new MyException();
}
} catch (MyException e) {
//e.printStackTrace();
exceptions.add(e);
}
try {
int[] arrayMin = new int[-4];
} catch (NegativeArraySizeException q) {
exceptions.add(q);
}
try {
Ultimate ultimate = new Ultimate();
} catch (Exception vsevolod) {
exceptions.add(vsevolod);
}
try {
String str[] = new String[15];
str[1] = 123;
} catch (ArrayStoreException stored) {
exceptions.add(stored);
}
try {
String str = "qwer";
Integer a = (Integer) str;
} catch (ClassCastException classed) {
exceptions.add(classed);
}
try {
String asd = 123 + 45;
} catch (Exception iDontKnow) {
exceptions.add(iDontKnow);
}
try {
Abstract asd = new Abstract();
} catch (InstantiationException zxc) {
exceptions.add(zxc);
}
try {
Solution.field = 123;
} catch (NoSuchFieldException e) {
exceptions.add(e);
}
}
public static class MyException extends Exception {
public MyException() {
super.getMessage();
System.out.print("Это мое исключение!");
}
}
abstract class Abstract {
}
}