* added helper
This commit is contained in:
parent
90951f7989
commit
2ce7c6020b
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue