1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04:00
filebot/source/net/filebot/util/ExceptionUtilities.java
2016-10-20 21:44:39 +08:00

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();
}
}