田源
2025-01-16 a13255b4129ee8a7a7b7e1ecd8e02dd2c78f7c17
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
package com.vci.starter.web.util;
 
 
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
 
/**
 * 多语相关的工具类
 * @author weidy
 */
public class LangBaseUtil {
    /**
     * 获取异常信息
     * @param e 异常对象
     * @return 异常对象上的所有内容
     */
    public static String getErrorMsg(Throwable e){
        if(e == null){
            return "未知错误";
        }
        if( e.getClass()!= null && e.getClass().getSuperclass()!= null &&
                (e.getClass().getSuperclass().equals(RuntimeException.class)
                        || e.getClass().getSuperclass().getName().endsWith(".VciBaseException")
                        || e.getClass().getName().endsWith(".VciBaseException"))){
            //说明是我们自定义的异常类
            try {
                Method errorMethod = e.getClass().getMethod("getErrorMsg");
                if(errorMethod != null ){
                    return (String)errorMethod.invoke(e);
                }
            } catch (NoSuchMethodException e1) {
                return e.getMessage();
            } catch (IllegalAccessException e1) {
                return e.getMessage();
            } catch (InvocationTargetException e1) {
                return e.getMessage();
            }
        }
        return e.getMessage();
    }
}