shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
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
49
50
51
52
53
54
55
56
package com.walker.infrastructure.core;
 
public class NestedRuntimeException extends RuntimeException {
 
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
 
    public NestedRuntimeException(String msg){
        super(msg);
    }
 
    public NestedRuntimeException(String msg, Throwable cause){
        super(msg, cause);
    }
 
    public String getMessage(){
        return NestedExceptionUtils.buildMessage(super.getMessage(), getCause());
    }
 
    public Throwable getRootCause(){
        Throwable rootCause = null;
        for(Throwable cause = getCause(); cause != null && cause != rootCause; cause = cause.getCause())
            rootCause = cause;
 
        return rootCause;
    }
 
    public Throwable getMostSpecificCause(){
        Throwable rootCause = getRootCause();
        return ((Throwable) (rootCause == null ? this : rootCause));
    }
 
    public boolean contains(Class<?> exType){
        if(exType == null)
            return false;
        if(exType.isInstance(this))
            return true;
        Throwable cause = getCause();
        if(cause == this)
            return false;
        if(cause instanceof NestedRuntimeException)
            return ((NestedRuntimeException)cause).contains(exType);
        do {
            if(cause == null)
                break;
            if(exType.isInstance(cause))
                return true;
            if(cause.getCause() == cause)
                break;
            cause = cause.getCause();
        } while(true);
        return false;
    }
}