/**
* 异常类
*
* @author
* @version 2014-08-06
*/
public class CredtiException extends Exception {
/**
*
*/
private static final long serialVersionUID = xxx;
private String errorCode = null;
/**
* <默认构造函数>
*/
public CredtiException() {
super();
}
/**
* 构造函数
*
* @param message 错误信息
*/
public CredtiException(String message) {
super(message);
setErrorCode(message);
}
/**
* 构造函数
*
* @param message 错误信息
* @param errorCode 错误码
*/
public CredtiException(String message, String errorCode) {
super(message);
setErrorCode(errorCode);
}
/**
* 构造函数
*
* @param t Throwable
*/
public CredtiException(Throwable t) {
super(t);
}
/**
* 构造函数
*
* @param t Throwable
* @param errorCode 错误码
*/
public CredtiException(Throwable t, String errorCode) {
super(t);
setErrorCode(errorCode);
}
public String getErrorCode() {
return errorCode;
}
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
}
- 1.自定义异常:
- class 异常类名 extends Exception
- {
- public 异常类名(String msg)
- {
- super(msg);
- }
- }
- 2.标识可能抛出的异常:
- throws 异常类名1,异常类名2
- 3.捕获异常:
- try{}
- catch(异常类名 y){}
- catch(异常类名 y){}
- 4.方法解释
- getMessage() //输出异常的信息
- printStackTrace() //输出导致异常更为详细的信息