自定义异常类

 

package {
	import flash.errors.*;
	public class MyError extends Error {
		private const eId:int = 15;
		private const eMessage:String = "Error Msg";
		private var gerTime:Date;

		public function MyError(repToServer:Boolean=true) {
			super(eMessage, eId);
			this.gerTime = new Date();
			if (repToServer) {
				reportToServer();
			}
		}
		private function reportToServer():void {
		}
		public function toString():String {
			return gerTime.toString()+"\n"+eId+","+eMessage;
		}
	}
}
try {
	throw new MyError  ;
} catch (e:MyError) {
	trace("错误编号: "+e.errorID+"\n");
	//trace("Error对象类型: "+e.constructor+"\n");
	trace("错误名称: "+e.name+"\n");
	trace("错误信息: "+e.message+"\n");
	trace("调用栈: "+e.getStackTrace+"\n");
} catch (e:Error) {

}

你可能感兴趣的:(自定义,as3,异常类)