⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tanghanexception.java

📁 J2EE eclipse 下开发数据库一个插件
💻 JAVA
字号:
/*
 * Created on 2003-4-14
 *
 */
package com.tanghan.util;

import java.util.ResourceBundle;
import java.util.ArrayList;
import org.apache.log4j.Logger;
/**
 * 
 * ToDo_Complete 设计Tanghan专用的Exception类
 * @author Jerry Tang
 * @version v0.1.0
 * @copyright  (C) 2003 Tanghan工作组
 *  */

public class TanghanException extends Exception {
	/**错误代码*/
	protected String errorCode = "TanghanDefaultError";
	/**错误列表*/
	protected static ResourceBundle resource = ResourceBundle.getBundle(TanghanConfig.getProperty("ErrorCodes.Resource"));
	/**额外错误列表*/
	protected static ArrayList resList = null;
	/**Logger的日志类*/
	protected static Logger log = Log.getInstanse().getLogger("TanghanException"); 
	
	/**得到引起额外的Exception*/
	protected Throwable cause = null;
	
	/**初始化而外错误列表*/
	protected synchronized static void initExtrErrRes(){
		resList = new ArrayList();
	}
	public static void addErrorCodeResource(ResourceBundle res){
		if(resList==null){
			initExtrErrRes();
		}
		resList.add(res);
	}
	/**
	 * 构造函数
	 */
	public TanghanException() {
		super();
		init();
	}

	/** 构造函数
	 * @param message 报错信息
	 */
	public TanghanException(String message) {
		super(message);
		init();
	}

	/** 构造函数
	 * @param message 报错信息
	 * @param cause 引发的上级错误
	 *  注意:在J2SDK1.4.0的Exception, 可以使用super(message, cause);
	 */
	public TanghanException(String message, Throwable cause) {
		//super(message, cause);
		super(message);
		this.cause = cause;
		init();
	}

	/** 构造函数
	 * @param cause 引发的上级错误
	 *  注意:在J2SDK1.4.0的Exception, 可以使用super( cause);
	 */
	public TanghanException(Throwable cause) {
		//super(cause);
		super(cause.getMessage());
		this.cause = cause;
		init();
	}
	/**初始化ErrorCode<br>
	 * 在继承TanghanException,必须覆盖该方法。
	 * */
	protected void init(){
		errorCode = "TanghanDefaultError";
	}

	/**
	 * @return 错误代码
	 */
	public String getErrorCode() {
		return errorCode;
	}

	/**
	 * @param string 错误代码
	 */
	public void setErrorCode(String string) {
		errorCode = string;
	}
	
	/**
	 * 根据Error Code得到相对应错误信息
	 * @return 错误信息
	 * */
	public String getErrorMessage(){
		String msg ="";
		try{
			msg = resource.getString(errorCode);
			//Todo 加入对额外错误信息的处理
		}catch(Exception e){
			log.debug("无法找到该errorCode相对应的错误信息",e);
		}
		return msg;
	}
	/**得到引起例外的Exception
	 * @return 引起例外的Exception
	 */
	public Throwable getCauseException() {
		return cause;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -