Java tutorial
/** * Copyright (c) 2005-2012 https://github.com/zhangkaitao * * Licensed under the Apache License, Version 2.0 (the "License"); */ package com.luna.common.exception; import com.luna.common.utils.MessageUtils; import org.springframework.util.StringUtils; /** * * <p>User: Zhang Kaitao * <p>Date: 13-3-11 ?8:19 * <p>Version: 1.0 */ public class BaseException extends RuntimeException { //? private String module; /** * ? */ private String code; /** * ?? */ private Object[] args; /** * ? */ private String defaultMessage; public BaseException(String module, String code, Object[] args, String defaultMessage) { this.module = module; this.code = code; this.args = args; this.defaultMessage = defaultMessage; } public BaseException(String module, String code, Object[] args) { this(module, code, args, null); } public BaseException(String module, String defaultMessage) { this(module, null, null, defaultMessage); } public BaseException(String code, Object[] args) { this(null, code, args, null); } public BaseException(String defaultMessage) { this(null, null, null, defaultMessage); } @Override public String getMessage() { String message = null; if (!StringUtils.isEmpty(code)) { message = MessageUtils.message(code, args); } if (message == null) { message = defaultMessage; } return message; } public String getModule() { return module; } public String getCode() { return code; } public Object[] getArgs() { return args; } public String getDefaultMessage() { return defaultMessage; } @Override public String toString() { return this.getClass() + "{" + "module='" + module + '\'' + ", message='" + getMessage() + '\'' + '}'; } }