testTry-catch和catch中的应用程序恢复
testTry-catch和catch中的应用程序恢复
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Button x="10" y="10" id="btn1" label="showError" click="showError()" fontSize="12"/>
<mx:Button x="10" y="63" label="Button" width="95" click="continueMute()" fontSize="12"/>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
var tArr:Array;
public function showError():void
{
var aStr:String;
try
{
aStr = tArr.toString();//tArr是个未初始化的数组,引用为null
}
catch (e:Error)
{
trace(e); // output: ArgumentError: Error #2024: An object may not be added as a child of itself.
tArr = [];
tArr.push("a");
btn1.label = "xxx";
Alert.show(e.toString());
continueMute();
}
}
public function continueMute():void
{
Alert.show("continueMute:" + tArr.toString());
}
]]>
</mx:Script>
</mx:Application>
本文探讨了在MXML应用中使用try-catch块进行异常处理,并在catch块中实现应用程序恢复的过程。通过实例展示了如何在捕获错误后清空数组、修改按钮标签并展示错误信息,最终调用继续恢复函数。

被折叠的 条评论
为什么被折叠?



