package com.qianwen.core.tool.utils;
|
|
import java.io.PrintWriter;
|
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.UndeclaredThrowableException;
|
import com.qianwen.core.tool.support.FastStringWriter;
|
|
/* loaded from: blade-core-tool-9.3.0.0-SNAPSHOT.jar:org/springblade/core/tool/utils/Exceptions.class */
|
public class Exceptions {
|
public static RuntimeException unchecked(Throwable e) {
|
if (e instanceof Error)
|
throw (Error)e;
|
if (e instanceof IllegalAccessException || e instanceof IllegalArgumentException || e instanceof NoSuchMethodException)
|
return new IllegalArgumentException(e);
|
if (e instanceof InvocationTargetException)
|
return new RuntimeException(((InvocationTargetException)e).getTargetException());
|
if (e instanceof RuntimeException)
|
return (RuntimeException)e;
|
if (e instanceof InterruptedException)
|
Thread.currentThread().interrupt();
|
|
return runtime(e);
|
}
|
|
private static <T extends Throwable> T runtime(Throwable throwable) throws T {
|
throw (T)throwable;
|
}
|
|
public static Throwable unwrap(Throwable wrapped) {
|
Throwable th = wrapped;
|
while (true) {
|
Throwable unwrapped = th;
|
if (unwrapped instanceof InvocationTargetException) {
|
th = ((InvocationTargetException) unwrapped).getTargetException();
|
} else if (unwrapped instanceof UndeclaredThrowableException) {
|
th = ((UndeclaredThrowableException) unwrapped).getUndeclaredThrowable();
|
} else {
|
return unwrapped;
|
}
|
}
|
}
|
|
public static String getStackTraceAsString(Throwable ex) {
|
FastStringWriter stringWriter = new FastStringWriter();
|
ex.printStackTrace(new PrintWriter(stringWriter));
|
return stringWriter.toString();
|
}
|
}
|