Hello again 😀.
One of my exceptions to not meeting the criteria.
I think, maybe line 114-116 ???
package pl.codegym.task.task14.task1419;
import java.util.ArrayList;
import java.util.List;
import java.io.BufferedReader;
import java.io.File;
//import java.io.FileNotFoundException;
import java.io.FileReader;
//import java.io.IOException;
/*
Inwazja wyjątków
*/
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() { // Pierwszy wyjątek
try {
float i = 1 / 0; // division by 0. ArithmeticException
} catch (Exception e) {
exceptions.add(e);
}
//tutaj wpisz swój kod
//..............2..............
try {
int[] table = {1,2,3};
System.out.println(table[3]); // Array index is out of bounds
} catch (Exception e) {
exceptions.add(e);
}
//..............3..............
try {
Object x[] = new String[3];
x[0] = new Integer(0); // Array Store Exception (Integer instead of Object)
} catch (Exception e) {
exceptions.add(e);
}
//..............4..............
try {
Object x = new Integer(0);
System.out.println((String)x); // Class Cast Exception
} catch (Exception e) {
exceptions.add(e);
}
//..............5..............
try {
String x = null;
String y = "B";
if ( x.equals(y)) { // Null Pointer Exception
System.out.println("yes");
}
} catch (Exception e) {
exceptions.add(e);
}
//..............6..............
try {
Class.forName("NoClassExist"); //Class Not Found Exception
} catch (Exception e) {
exceptions.add(e);
}
//..............7..............
try {
File file = new File("someRandomName.txt"); //File Not Found Exception
FileReader fileReader = new FileReader(file);
BufferedReader bfReader = new BufferedReader(fileReader);
bfReader.lines().forEach(System.out::println);
bfReader.close();
} catch (Exception e) {
exceptions.add(e);
}
//..............8..............
try {
// Illegal Thread State Exception
NewThread t = new NewThread();
// starting the above created thread using the start() method
t.start();
// displaying the text
System.out.println("This is main thread");
// starting the thread again when it is already running
// this gives an exception
t.start();
} catch (Exception e) {
exceptions.add(e);
}
//..............9..............
try {
TestInterruptingThread1 t1=new TestInterruptingThread1(); //Interrupted Exception
t1.start();
t1.interrupt();
} catch (Exception e) {
exceptions.add(e);
}
//..............10..............
try {
throw new MyException();
} catch (Exception e) { // User Defined Exception
exceptions.add(e);
}
}
}
class NewThread extends Thread {
public void run()
{
for (int i = 0; i < 3; i++) {
System.out.println("This is example of IllegalStateException");
}
}
}
class TestInterruptingThread1 extends Thread {
public void run() {
try {
Thread.sleep(1000);
System.out.println("task");
} catch (InterruptedException e) {
throw new RuntimeException("Thread interrupted..." + e);
}
}
}
class MyException extends Exception {
}