Ребят, привет!
Эт мои исключения. Все уникальны, но валидатор не согласен.
А что думаете вы?
Вывод:
java.lang.ArithmeticException: / by zero
java.lang.NullPointerException
java.lang.ArrayIndexOutOfBoundsException: 3
java.lang.ArrayStoreException: java.lang.Integer
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
java.io.FileNotFoundException: notes3.txt (Не удается найти указанный файл)
java.lang.NumberFormatException: For input string: "d"
java.lang.NegativeArraySizeException
java.util.EmptyStackException
java.util.NoSuchElementException
package com.javarush.task.task14.task1419;
import java.io.File;
import java.io.FileReader;
import java.util.*;
/*
Нашествие исключений
*/
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; //1
} catch (Exception e) {
exceptions.add(e);
}
String a = null;
String b= "d";
try {a.equals(b);}
catch (Exception e){exceptions.add(e);} //2
int [] s = {1,2,3};
try { System.out.println(s[3]);}
catch (Exception e){exceptions.add(e);} //3
try { Object x[] = new String[3]; //4
x[0] = new Integer(0);}
catch (Exception e){exceptions.add(e);}
try { Object x = new Integer(0); //5
System.out.println((String)x);}
catch (Exception e){exceptions.add(e);}
try{FileReader reader = new FileReader("notes3.txt");} //6
catch (Exception e){exceptions.add(e);}
int g=0;
try{g= Integer.parseInt(b);}
catch (Exception e){exceptions.add(e);} //7
Map<Integer, Integer> h = new HashMap<>();
try { Object y[] = new String[-3]; } //8
catch (Exception e){exceptions.add(e);}
try { Stack st = new Stack();
st.empty();
st.peek();}
catch (Exception e){exceptions.add(e);} //9
try { Scanner file=new Scanner(new File("D:\\huk.txt"));
while(!file.next().equals("treasure")){
file.next();
}}
catch (Exception e){exceptions.add(e);} //10
//напишите тут ваш код
}
public static void iI (String b){
System.out.println(b);
}
}