2008-06-09 14:36:05 -04:00
|
|
|
|
|
|
|
package net.sourceforge.tuned;
|
|
|
|
|
|
|
|
|
2009-02-09 15:56:20 -05:00
|
|
|
public final class ExceptionUtilities {
|
2008-06-09 14:36:05 -04:00
|
|
|
|
|
|
|
public static Throwable getRootCause(Throwable t) {
|
|
|
|
while (t.getCause() != null) {
|
|
|
|
t = t.getCause();
|
|
|
|
}
|
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-10 16:51:02 -05: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()) {
|
2009-02-15 07:20:43 -05:00
|
|
|
message = t.toString().replaceAll(t.getClass().getName(), t.getClass().getSimpleName());
|
2009-02-10 16:51:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-09 14:36:05 -04:00
|
|
|
public static RuntimeException asRuntimeException(Throwable t) {
|
|
|
|
if (t instanceof RuntimeException) {
|
|
|
|
return (RuntimeException) t;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new RuntimeException(t);
|
|
|
|
}
|
|
|
|
|
2008-10-10 15:20:37 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dummy constructor to prevent instantiation.
|
|
|
|
*/
|
2009-02-09 15:56:20 -05:00
|
|
|
private ExceptionUtilities() {
|
2008-10-10 15:20:37 -04:00
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
2008-06-09 14:36:05 -04:00
|
|
|
}
|