I do not know which exceptions are the same
package com.codegym.task.task14.task1419;
import java.io.*;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.net.*;
/*
Exception invasion
*/
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;
}
catch(Exception e) { // 1
exceptions.add(e);
}
//write your code here
try
{
String string = null;
}
catch(NullPointerException e) // 2
{
exceptions.add(e);
}
try
{
int n = 1;
}
catch(NumberFormatException e) // 3
{
exceptions.add(e);
}
try
{
int[] array = new int[5]; //4
}
catch(IndexOutOfBoundsException e)
{
exceptions.add(e);
}
try
{
BufferedReader bufer = new BufferedReader(new FileReader("C:\\archivo.txt")); //5
}
catch(IOException e)
{
exceptions.add(e);
}
try
{
Object i = Integer.valueOf(5);
String s = (String)i;
}
catch(ClassCastException e) //6
{
exceptions.add(e);
}
try
{
int i = Integer.valueOf("5");
}
catch(ArithmeticException e) // 7
{
exceptions.add(e);
}
try
{
FileReader reader = new FileReader("C\\miarchivo");
}
catch(FileNotFoundException e) // 8
{
exceptions.add(e);
}
try
{
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
}
catch(NoSuchElementException e) //9
{
exceptions.add(e);
}
try
{
URL url = new URL("wwwww.Hola.com");
} catch (MalformedURLException e) // 10
{
exceptions.add(e);
}
}
}