Валидатор ругается и говорит "Список exceptions должен содержать 10 элементов."
Проверяю в IDEA список состоит из 10 уникальных элементов. Убил кучу времени на эту задачу и не понятно зачем.
package com.javarush.task.task14.task1419;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/*
Нашествие исключений
*/
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() { //the first exception
try {
float i = 1 / 0;
} catch (Exception e) {
exceptions.add(e);
}
try {
int c[] = {1};
c[3] = 48;
} catch (Exception e) {
exceptions.add(e);
}
try {
Object x = new Integer(0);
System.out.println((String)x);
} catch (Exception e) {
exceptions.add(e);
}
try {
String s = null;
if (s.equals("")){
return;
}
} catch (Exception e) {
exceptions.add(e);
}
try {
BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\Username\\Desktop\\test.txt"));
String firstString = reader.readLine();
} catch (Exception e) {
exceptions.add(e);
}
try {
int a = -4 ;
int b [] = new int [a];
} catch (Exception e) {
exceptions.add(e);
}
try {
String a = "_____";
int b = Integer.parseInt(a);
} catch (Exception e) {
exceptions.add(e);
}
try {
Object szStr[] = new String[10];
szStr[0] = new Character('*');
} catch (Exception e) {
exceptions.add(e);
}
try {
String szShortString = "123";
char chr = szShortString.charAt(10);
} catch (Exception e) {
exceptions.add(e);
}
try {
ServerSocket server = new ServerSocket(-1);
} catch (Exception e) {
exceptions.add(e);
}
}
}