filebot/source/net/sourceforge/tuned/ExceptionUtilities.java

49 lines
822 B
Java
Raw Normal View History

package net.sourceforge.tuned;
public final class ExceptionUtilities {
public static Throwable getRootCause(Throwable t) {
while (t.getCause() != null) {
t = t.getCause();
}
return t;
}
2009-02-10 21:51:02 +00:00
public static String getRootCauseMessage(Throwable t) {
return getMessage(getRootCause(t));
}
public static String getMessage(Throwable t) {
String message = t.getMessage();
if (message == null || message.isEmpty()) {
return t.toString();
}
return message;
}
public static RuntimeException asRuntimeException(Throwable t) {
if (t instanceof RuntimeException) {
return (RuntimeException) t;
}
return new RuntimeException(t);
}
2008-10-10 19:20:37 +00:00
/**
* Dummy constructor to prevent instantiation.
*/
private ExceptionUtilities() {
2008-10-10 19:20:37 +00:00
throw new UnsupportedOperationException();
}
}