yangys
2024-03-31 2969df3e404db3cd116f27db1495e523ce05bf86
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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();
    }
}