All exceptions are unique. Why this requirement is not fullfilled?
package com.codegym.task.task14.task1419;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/*
Exception invasion
*/
public class Solution {
public static List<Exception> exceptions = new ArrayList<Exception>();
public static void main(String[] args) {
initExceptions();
//System.out.println(new File("").getAbsolutePath());
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 {
Scanner sc = new Scanner(new FileInputStream("open.txt"));
} catch (Exception e) {
exceptions.add(e);
}
try (Scanner sc = new Scanner(new FileInputStream("output.txt"))) {
sc.nextInt();
} catch (Exception e) {
exceptions.add(e);
}
try {
int[] ints = {1, 2, 3};
for (int i = 0; i < 4; i++) {
ints[i] = i;
}
} catch (Exception e) {
exceptions.add(e);
}
try (Scanner sc = new Scanner(new FileInputStream("output.txt"))) {
while (true)
sc.nextLine();
} catch (Exception e) {
exceptions.add(e);
}
try {
Object[] obj = {"one", "twu", "three"};
for (Object o : obj) {
Integer integ = Integer.parseInt((String) o);
}
} catch (Exception e) {
exceptions.add(e);
}
try {
String line = null;
char ch = line.charAt(0);
} catch (Exception e) {
exceptions.add(e);
}
try {
String line = "null";
char ch = line.charAt(4);
} catch (Exception e) {
exceptions.add(e);
}
try {
Object[] x = new String[3];
x[0] = new Integer(0);
} catch (Exception e) {
exceptions.add(e);
}
try {
String[] dateStr = new String[-5];
} catch (Exception e) {
exceptions.add(e);
}
}
}