,
package com.javarush.task.task14.task1419;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
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() { //it's first exception
try {
float i = 1 / 0;
} catch (Exception e) {
exceptions.add(e);
} //1
try {
String s = null;
String m = s.toLowerCase();
} catch (NullPointerException n) {
exceptions.add(n);
} //2
try {
ArrayList<String> list = new ArrayList<String>();
String s = list.get(18);
} catch (IndexOutOfBoundsException in) {
exceptions.add(in);
} //4
//напишите тут ваш код
try {
int num = Integer.parseInt("XYZ");
System.out.println(num);
} catch (NumberFormatException n) {
exceptions.add(n);
}//5
try {
HashMap<String, String> map = new HashMap<String, String>(null);
map.put(null, null);
map.remove(null);
} catch (NullPointerException np) {
exceptions.add(np);
}//6
try {
int[] m = new int[2];
m[8] = 5;
} catch (ArrayIndexOutOfBoundsException ar) {
exceptions.add(ar);
} //7
try {
if (System.currentTimeMillis() % 2 == 0) {
throw new EOFException();
} else {
throw new FileNotFoundException();
}
} catch (EOFException e) {
exceptions.add(e);
// ... 8
} catch (FileNotFoundException e) {
exceptions.add(e);
//9
}
String siteUrl = "";
URL url;
try {
url = new URL(siteUrl);
} catch (MalformedURLException mal) {
exceptions.add(mal);
}//9
StringReader reader = new StringReader("qwerty");
// try {
// reader.read();
// }
// catch (IOException xxx) { /* cannot happen */
//
// exceptions.add(xxx);
// System.out.println("xxx");
// }
// try {
// FileWriter fileWriter = new FileWriter("out.txt");
// fileWriter.close();
// fileWriter.write("Hello World");
// } catch (IOException ioe) {
// exceptions.add(ioe);
// }
Object szStr[] = new String[10];
try
{
szStr[0] = new Character('*');
}
catch(Exception ex)
{
exceptions.add(ex);
// System.out.println(ex.toString());
}
try
{
int[] nNegArray = new int[-5];
}
catch(Exception exe)
{
exceptions.add(exe);
//System.out.println(ex.toString());
}
}
}