Commit f79c6734 authored by yanzg's avatar yanzg

修改实例化关系

parent 0031b938
package com.yanzuoguang.util;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.helper.StringHelper;
import java.util.HashMap;
import java.util.Map;
/**
* 系统错误编码
*
* @author 颜佐光
*/
public class YzgError {
/**
* 错误标记
*/
public static final String TAG = "999.";
/**
* 错误缓存消息
*/
private static Map<String, String> ErrorCode = new HashMap<>();
private static void init() {
add("001", "");
}
private static void initTemp() {
}
public static void add(String code, String message) {
ErrorCode.put(code, message);
}
/**
* 抛出异常
*
* @param code
* @param args
*/
public static CodeException throwException(String code, Object... args) {
throw getException(null, code, args);
}
/**
* 抛出异常
*
* @param code
* @param args
*/
public static CodeException throwException(Exception ex, String code, Object... args) {
throw getException(ex, code, args);
}
/**
* 抛出异常
*
* @param code
* @param args
*/
public static CodeException getException(String code, Object... args) {
return getException(null, code, args);
}
/**
* 抛出异常
*
* @param code
* @param args
*/
public static CodeException getException(Exception ex, String code, Object... args) {
return getException(ErrorCode, TAG, ex, code, args);
}
/**
* 抛出异常
*
* @param code
* @param args
*/
public static CodeException getException(Map<String, String> ErrorCode, String tag, Exception ex, String code, Object... args) {
String message = ErrorCode.get(code);
if (StringHelper.isEmpty(message)) {
message = "未知错误" + JsonHelper.serialize(args);
} else {
try {
message = String.format(message, args);
} catch (Exception e) {
e.printStackTrace();
}
}
if (ex != null) {
return new CodeException(tag + code, message, ex);
} else {
return new CodeException(tag + code, message);
}
}
static {
init();
initTemp();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment