1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-04 16:35:08 -05:00

* added helper

This commit is contained in:
Reinhard Pointner 2014-07-28 12:54:27 +00:00
parent 90951f7989
commit 2ce7c6020b

View File

@ -1,6 +1,7 @@
package net.filebot.util;
import java.io.PrintWriter;
import java.io.StringWriter;
public final class ExceptionUtilities {
@ -12,7 +13,6 @@ public final class ExceptionUtilities {
return t;
}
public static <T extends Throwable> T findCause(Throwable t, Class<T> type) {
while (t != null) {
if (type.isInstance(t))
@ -24,12 +24,10 @@ public final class ExceptionUtilities {
return null;
}
public static String getRootCauseMessage(Throwable t) {
return getMessage(getRootCause(t));
}
public static String getMessage(Throwable t) {
String message = t.getMessage();
@ -40,6 +38,11 @@ public final class ExceptionUtilities {
return message;
}
public static String getStackTrace(Throwable t) {
StringWriter buffer = new StringWriter();
t.printStackTrace(new PrintWriter(buffer, true));
return buffer.getBuffer().toString();
}
public static <T extends Throwable> T wrap(Throwable t, Class<T> type) {
if (type.isInstance(t)) {
@ -53,12 +56,10 @@ public final class ExceptionUtilities {
}
}
public static RuntimeException asRuntimeException(Throwable t) {
return wrap(t, RuntimeException.class);
}
/**
* Dummy constructor to prevent instantiation.
*/