mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-11 20:05:04 -05:00
44 lines
805 B
Java
44 lines
805 B
Java
package net.filebot.util;
|
|
|
|
public final class ExceptionUtilities {
|
|
|
|
public static Throwable getRootCause(Throwable t) {
|
|
if (t != null) {
|
|
while (t.getCause() != null) {
|
|
t = t.getCause();
|
|
}
|
|
}
|
|
return t;
|
|
}
|
|
|
|
public static <T extends Throwable> T findCause(Throwable t, Class<T> type) {
|
|
while (t != null) {
|
|
if (type.isInstance(t)) {
|
|
return type.cast(t);
|
|
}
|
|
t = t.getCause();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static String getRootCauseMessage(Throwable t) {
|
|
return getMessage(getRootCause(t));
|
|
}
|
|
|
|
public static String getMessage(Throwable t) {
|
|
if (t != null) {
|
|
String m = t.getMessage();
|
|
if (m == null || m.isEmpty()) {
|
|
return t.toString();
|
|
}
|
|
return m;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private ExceptionUtilities() {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
}
|