package {
import flash.display.Sprite;
[SWF(width="400",height="300",backgroundColor="#00ffee",frameRate="32")]
public class actionscript3 extends Sprite
{
public function actionscript3():void {
}
//异常处理
//try/throw/catch
//当throw抛出异常时,会中断当前执行,自动寻找catch的语句块
/*
try{
throw()
}catch(){
}final{
}
*/
public function drawRectangle(sprite:Sprite , nWidth:Number , nHeight:Number ):void{
if (isNaN(nWidth) || isNaN(nHeight)){
throw new Error();
}
this.graphics.lineStyle(1,0,1);
this.graphics.lineTo(nWidth,0);
this.graphics.lineTo(nWidth,nHeight);
this.graphics.lineTo(0,nHeight);
this.graphics.lineTo(0,0);
}
}
}
var _drawRectangle:actionscript3 = new actionscript3;
try{
this.drawRectangle(this,2,3);
}catch(errObject:Error){
trace("try again!!");
}finally{
trace("thanks"); //finally语句,一定会被执行
}
结果如下:
阅读(1494) | 评论(0) | 转发(0) |