Произошла ошибка дополнительной информации нет, в чем может быть причина? Прописал 10 разных исключений, комментариями отметил, где какие..
package com.javarush.task.task14.task1419;
import java.util.ArrayList;
import java.util.List;
import java.io.*;
import java.util.*;
import java.text.SimpleDateFormat;
/*
Нашествие исключений
*/
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
// 1.Exception
try {
float i = 1 / 0;
} catch (Exception e)
{exceptions.add(e); }
//напишите тут ваш код
// 2. NegativeArraySizeException
try {
int n=3;
int m=2;
int r=m-n;
int[] numbers = new int[r];
}
catch(Exception e)
{ exceptions.add(e); }
// 3.FileNotFoundException
try{
FileInputStream fis = new FileInputStream("C2:\badFileName.txt");
}
catch (Exception e)
{ exceptions.add(e); }
// 4.ArithmeticException
try{
int b = 1/0;
}
catch (Exception e)
{ exceptions.add(e); }
// 5.ClassCastException
try{
String s = new String("Cast");
Object o = (Object) s;
Object o1 = new Object();
String s1 = (String)o1;
}
catch(Exception e)
{ exceptions.add(e); }
// 6.NullPointerException
try{
String snul = null;
snul.toUpperCase();
}
catch(Exception e)
{ exceptions.add(e); }
// 7.ArrayIndexOutOfBoundsException
try{
int array[] = { 1,2,3};
System.out.println(array[4]);
}
catch(Exception e)
{ exceptions.add(e); }
// 8.ArrayStoreException
try{
Object[] x = new String[3];
x[0] = new Integer(1);
}
catch(Exception e)
{ exceptions.add(e); }
// 9.StringIndexOutOfBoundsException
try{
String str = "Hello";
char c = str.charAt(24);
}
catch(Exception e)
{ exceptions.add(e); }
// 10.NumberFormatException
try{
int num = Integer.parseInt("Hello");
System.out.println(num);
}
catch(Exception e)
{ exceptions.add(e); }
// 11.illegalArgumentException
try{
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM d yyyy");
String s = "2020-01-01";
dateFormat.format(s);
}
catch(Exception e)
{ exceptions.add(e); }
}
}