I don't know why the first exception did not want to be added to my Arraylist?
package com.codegym.task.task25.task2512;
/*
Charting our own course
*/
import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Stack;
public class Solution implements Thread.UncaughtExceptionHandler {
@Override
public void uncaughtException(Thread t, Throwable e) {
//Why we use here interupt?
t.interrupt();
//Creating Arraylist to add all created exceptions
ArrayList<Throwable> list = new ArrayList<Throwable>();
//Getting the first exception
Throwable ie = e.getCause();
while (ie != null){
list.add(ie);
//asking for the next exception on the Stack trace?
ie = ie.getCause();
}
for (int i = list.size()-1; i >=0; i--) {
System.out.println(list.get(i).getClass().getName() +":"+list.get(i).getMessage());
}
}
public static void main(String[] args) throws Exception {
Solution s = new Solution();
Thread.currentThread().setDefaultUncaughtExceptionHandler(s);
throw new Exception("ABC", new RuntimeException("DEF", new IllegalAccessException("GHI")));
}
}