Смоделировала 10 разных ситуаций, но Список exceptions должен содержать 10 элементов. не проходит
мозг поломала уже, что не так. Благодарна за подсказку
java.lang.ArithmeticException: / by zero
java.lang.ClassCastException: java.lang.Object cannot be cast to java.lang.String
java.net.SocketException: Network is unreachable: connect
java.net.MalformedURLException: no protocol:
java.lang.NullPointerException
java.lang.ArrayStoreException: java.lang.Character
java.lang.ArrayIndexOutOfBoundsException: 11
java.lang.IndexOutOfBoundsException: Index: 5, Size: 0
java.lang.NumberFormatException: For input string: "qwe"
java.lang.CloneNotSupportedException: com.javarush.task.task14.task1419.Solution
package com.javarush.task.task14.task1419;
import java.io.*;
import java.net.Socket;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/*
Нашествие исключений
*/
public class Solution {
public static List<Exception> exceptions = new ArrayList<Exception>();
public static void main(String[] args) {
initExceptions();
//int i = 0;
for (Exception exception : exceptions) {
//System.out.println(i++);
System.out.println(exception);
}
}
private static void initExceptions() {
//1
try {
float i = 1 / 0;
}
catch (Exception e) {
exceptions.add(e);
}
//2
try {
String s = (String ) new Object();
s.toString();
}catch (Exception e){
exceptions.add(e);
}
//3
try {
Socket socket = new Socket("123", 8080);
} catch (Exception e){
exceptions.add(e);
}
//4
try {
URL url = new URL("");
} catch (Exception e){
exceptions.add(e);
}
//5
try {
Object obj = null;
obj.hashCode();
} catch (Exception e){
exceptions.add(e);
}
//6
try {
Object szStr[] = new String[10];
szStr[0] = new Character('*');
} catch (Exception e){
exceptions.add(e);
}
//7
try {
int[] myArray = new int[10];
System.out.println(myArray[11]);
} catch (Exception e){
exceptions.add(e);
}
//8
try {
ArrayList<String> arrayList = new ArrayList<>();
arrayList.get(5);
} catch (Exception e){
exceptions.add(e);
}
//9
try {
Integer.parseInt("qwe");
} catch (Exception e){
exceptions.add(e);
}
//10
try {
new Solution().clone();
} catch (Exception e){
exceptions.add(e);
}
}
}