admin
2024-04-24 363457b34e0e4f26ffe51aa80ecb227bf7873308
提交 | 用户 | 时间
363457 1 package com.jcdm.common.exception.base;
A 2
3 import com.jcdm.common.utils.MessageUtils;
4 import com.jcdm.common.utils.StringUtils;
5
6 /**
7  * 基础异常
8  * 
9  * @author jc
10  */
11 public class BaseException extends RuntimeException
12 {
13     private static final long serialVersionUID = 1L;
14
15     /**
16      * 所属模块
17      */
18     private String module;
19
20     /**
21      * 错误码
22      */
23     private String code;
24
25     /**
26      * 错误码对应的参数
27      */
28     private Object[] args;
29
30     /**
31      * 错误消息
32      */
33     private String defaultMessage;
34
35     public BaseException(String module, String code, Object[] args, String defaultMessage)
36     {
37         this.module = module;
38         this.code = code;
39         this.args = args;
40         this.defaultMessage = defaultMessage;
41     }
42
43     public BaseException(String module, String code, Object[] args)
44     {
45         this(module, code, args, null);
46     }
47
48     public BaseException(String module, String defaultMessage)
49     {
50         this(module, null, null, defaultMessage);
51     }
52
53     public BaseException(String code, Object[] args)
54     {
55         this(null, code, args, null);
56     }
57
58     public BaseException(String defaultMessage)
59     {
60         this(null, null, null, defaultMessage);
61     }
62
63     @Override
64     public String getMessage()
65     {
66         String message = null;
67         if (!StringUtils.isEmpty(code))
68         {
69             message = MessageUtils.message(code, args);
70         }
71         if (message == null)
72         {
73             message = defaultMessage;
74         }
75         return message;
76     }
77
78     public String getModule()
79     {
80         return module;
81     }
82
83     public String getCode()
84     {
85         return code;
86     }
87
88     public Object[] getArgs()
89     {
90         return args;
91     }
92
93     public String getDefaultMessage()
94     {
95         return defaultMessage;
96     }
97 }