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

📄 bsexception.java

📁 java已定义的异常类一般情况下能满足开发应用
💻 JAVA
字号:
package com.cdb.gbms.loan.student.bs.exception;

import java.util.Locale;


import com.cdb.gbms.loan.student.bs.exception.BSLocalizableMessage;

public class BSException extends Exception {
	// 嵌套的异常
	private Exception nestedException = null;

	// 资源
	public static String resource = "com.cdb.gbms.loan.student.bs.BSExceptionResource";

	/**
	 * 100:服务器与数据库连接失败 101:请求服务器错误:与服务端通信时产生错误
	 */
	private int errorNumber = 0;

	/**
	 * 用字符串构造异常,可直接输出
	 * 
	 * @param s
	 *            异常信息
	 */
	public BSException(String s) {
		super(s);
	}

	/**
	 * 默认构造函数
	 */
	public BSException() {
		super();
	}

	/**
	 * 嵌套异常
	 * 
	 * @param ex
	 *            异常实例
	 */
	public BSException(Exception ex) {
		nestedException = ex;
	}

	/**
	 * 嵌套异常并直接输出信息
	 * 
	 * @param ex
	 *            异常实例
	 * @param s
	 *            输出信息
	 */
	public BSException(Exception ex, String s) {
		super(s);
		nestedException = ex;
	}

	/**
	 * 参数化异常信息
	 * 
	 * @param s
	 *            是资源类名
	 * @param s1
	 *            是信息的键值
	 * @param aobj
	 *            是参数信息
	 */

	public BSException(String s, String s1, Object aobj[]) {
		super(BSMessage.getLocalizedMessage(s, s1, aobj, getLocale()));
	}

	/**
	 * 参数化异常信息
	 * 
	 * @param s
	 *            是资源类名
	 * @param s1
	 *            是信息的键值
	 */
	public BSException(String s, String s1) {
		super(BSMessage.getLocalizedMessage(s, s1, null, getLocale()));
	}

	/**
	 * 带嵌套异常的参数化异常信息
	 * 
	 * @param ex
	 *            嵌套的异常
	 * @param s
	 *            是资源类名
	 * @param s1
	 *            是信息的键值
	 * @param aobj
	 *            是参数信息
	 */
	public BSException(Exception ex, String s, String s1, Object aobj[]) {
		super(BSMessage.getLocalizedMessage(s, s1, aobj, getLocale()));
		nestedException = ex;
	}

	public void setErrorNumber(int num) {
		errorNumber = num;
	}

	public int getErrorNumber() {
		return errorNumber;
	}

	/**
	 * 获取当前locale
	 */
	private static Locale getLocale() {
		return Locale.CHINA;
	}

	/**
	 * 获取嵌套异常
	 */
	public Exception getNestedException() {
		return nestedException;
	}

	/**
	 * 打印异常堆栈
	 */
	public void printStackTrace() {
		super.printStackTrace();
		Exception ex = getNestedException();
		if (ex != null) {
			ex.printStackTrace();
			return;
		}
	}

	/**
	 * 获取本地信息
	 */
	public String getLocalMessage() {
		if (this.getMessage() == null || this.getMessage().equals("")) {
			return super.toString();
		} else {
			return super.toString() + " : " + this.getMessage() + ";";
		}
	}

	/**
	 * 输出信息
	 */
	public String toString() {
		String s = "";
		if (nestedException != null) {
			Locale locale1 = getLocale();
			if (locale1 == Locale.US) {
				s = "\n" + "nestedException is:"
						+ nestedException.getClass().getName() + ":"
						+ nestedException.toString();
			} else {
				s = "\n" + "嵌套的异常是:" + nestedException.getClass().getName()
						+ ":" + nestedException.toString();
			}
		}
		return getLocalMessage() + s;
	}

	/**
	 * 输出用于客户端显示的简单信息
	 */
	public String getClientMessage() {
		if (this.getMessage() == null || this.getMessage().equals("")) {
			if (nestedException != null) {

				if (nestedException instanceof BSException) {
					return ((BSException) nestedException).getClientMessage();
				}
				return nestedException.getMessage();
			}

			return this.getMessage();
		}
		return this.getMessage();
	}

}

⌨️ 快捷键说明

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