Неизвестая ошибка
package com.javarush.task.task25.task2512;
import java.util.ArrayList;
import java.util.Collections;
/*
Живем своим умом
*/
public class Solution implements Thread.UncaughtExceptionHandler {
/*Output java.lang.IllegalAccessException: GHI
java.lang.RuntimeException: DEF
java.lang.Exception: ABC*/
@Override
public void uncaughtException(Thread t, Throwable e) {
Thread.currentThread().interrupt();
// System.out.println(e); // java.lang.Exception: ABC
// System.out.println(e.getCause()); // java.lang.RuntimeException: DEF
// System.out.println(e.getCause().getCause()); // java.lang.IllegalAccessException: GHI
// System.out.println(e.getCause().getCause().getCause()); // null
ArrayList<Throwable> list = new ArrayList<>();
while (e != null) {
list.add(e);
e = e.getCause();
}
Collections.reverse(list);
for (Throwable throwable : list) {
System.out.println(throwable);
}
}
public static void main(String[] args) throws Exception {
// Thread.setDefaultUncaughtExceptionHandler(new Solution());
// // самый вложенный
// throw new Exception("ABC", new RuntimeException("DEF", new IllegalAccessException("GHI")));
}
}