Java 自定义错误类【转】
原文地址 :[url] http://www.cnblogs.com/likwo/archive/2010/08/03/1791187.html[/url]
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->public class MyException extends Exception{ private static final long serialVersionUID = 1L; private Type type; public MyException( Type type ) { super(); this.type = type; } public MyException( Throwable t, Type type ) { super( t ); this.type = type; } public String toString() { return super.toString() + "<" + getErrorType().getErrorCode() + ">"; } public Type getErrorType() { return type; } public enum Type { // 系统错误 SYSTEM_ERROR( "99999" ), // 用户认证错误 USER_AUTH( "03003" ); private String errorCode; Type( String errorCode ) { this.errorCode = errorCode; } public String getErrorCode() { return this.errorCode; } }}