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

📄 baseexception.java

📁 为了下东西 随便发了个 datamining 的源代码
💻 JAVA
字号:
/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

package eti.bi.exception; 


import java.util.Calendar;

import eti.bi.common.System.SysConfig;
/**
 * @author kjor
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class BaseException extends java.lang.Exception{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected String m_id;
	protected Throwable m_cause;
	protected String m_callingString;
	protected String m_mesg;
	final private static String m_messageId = "EXP00001";

	/**
	 * Constructor for BIAppException.
	 */
	public BaseException()
	{
		super();
	}

	/**
	 * Constructor for BIAppException.
	 * @param arg0
	 */
	public BaseException(String arg0)
	{
		super(arg0);
	}

	/**
	 * Constructor for BIAppException.
	 * @param arg0
	 */
	public BaseException(Throwable arg0)
	{
		super(arg0);
	}

	/**
	 * Constructor for BIAppException.
	 * @param arg0
	 * @param arg1
	 */
	public BaseException(String arg0, Throwable arg1)
	{
		super(arg0, arg1);
	}
		
	/**
	 * Constructor for BaseException.
	 * @param cause
	 * @param obj
	 */
	public BaseException(Throwable cause, Object[] obj) {
		this(cause, obj, "");
	}
	/**
	 * Constructor for AppException.
	 * @param obj
	 */
	public BaseException(Object[] obj) {
		this(null, obj, "");
	}

	public BaseException(Object[] obj, String mesg)
	{
		generateID();
		buildCallingMessage(obj,mesg);
	}

	public BaseException(Throwable cause, Object[] obj, String mesg)
	{
		//Do not generate a new ID if the caused exception is a BIException
		if (cause!=null && !(cause instanceof BaseException))
		{
			generateID();
		}
		m_cause = cause;
		buildCallingMessage(obj,mesg);
	}
	
	private void buildCallingMessage(Object[] obj, String mesg)
	{
		StackTraceElement[] stElement = this.getStackTrace();
		m_mesg = mesg;
		StringBuffer sBuffer = new StringBuffer();
		sBuffer.append(stElement[0].getClassName());
		sBuffer.append(".");
		sBuffer.append(stElement[0].getMethodName());
		sBuffer.append("(");
		for (int i=0;i<obj.length;i++)
		{
			if (i!=0) sBuffer.append(",");
			sBuffer.append(obj[i].toString());
		}	
		sBuffer.append("):");
		sBuffer.append(stElement[0].getLineNumber());
		m_callingString = sBuffer.toString();
	}

	public Throwable getCause()
	{
		return m_cause;
	}

	public String getCallingString()
	{
		return m_callingString;
	}
	
	public String getMessage()
	{
		return m_mesg;	
	}

	protected String getMessageString(String aMessageId)
	{
		try
		{
			String aMessage = SysConfig.getExceptionMessage(aMessageId);
			return aMessage;
		}catch(BaseException e)
		{
			return "Null Exception Message";
		}
	}

	protected void setMessage(String aMessage)
	{
		StringBuffer aBuffer = new StringBuffer();
		aBuffer.append(getMessageString(m_messageId));
		aBuffer.append("[");
		aBuffer.append(m_id);
		aBuffer.append("]");
		aBuffer.append(aMessage);
		m_mesg = aBuffer.toString();
	}

	public String getStack()
	{
		StringBuffer sBuffer = new StringBuffer();
//		sBuffer.append("EXCEPTION: "+m_id+"\n");
		sBuffer.append(m_callingString);
//		sBuffer.append(" <<"+m_mesg+">>");
		sBuffer.append("\n");
		Throwable t = this.getCause(); 
		while(t!=null)
		{
			if (t instanceof eti.bi.exception.BaseException)
			{
				sBuffer.append(((eti.bi.exception.BaseException)t).getCallingString());
				sBuffer.append(" <<"+((eti.bi.exception.BaseException)t).getMessage()+">>");
				sBuffer.append("\n");
				t = t.getCause();
			}else
			{
				sBuffer.append(" <<"+t.getMessage()+">>");
				break;
			}
		}
		return sBuffer.toString();
	}
	
	public String getID()
	{
		return m_id;
	}

	private void generateID()
	{
		Calendar aCalendar = Calendar.getInstance();
		StringBuffer sBuffer = new StringBuffer();
		sBuffer.append(aCalendar.get(Calendar.MONTH));
		sBuffer.append(aCalendar.get(Calendar.DAY_OF_WEEK));
		sBuffer.append(aCalendar.get(Calendar.HOUR_OF_DAY));
		sBuffer.append(aCalendar.get(Calendar.MINUTE));
		sBuffer.append(aCalendar.get(Calendar.SECOND));
		m_id = sBuffer.toString();								
	}

}

⌨️ 快捷键说明

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