【发布时间】:2009-04-01 09:59:29
【问题描述】:
我在以下 Actionscript 3 代码中使用了 try-catch 块:
try {
this._subtitle = new SubtitleController(subtitlePath, _framerate);
this._subtitle.addEventListener(Event.COMPLETE, subtitleLoaded);
}
catch (e:Error) {
trace('subtitle not found');
}
SubtitleController 构造函数然后尝试加载subtitlePath 并抛出Error #2044: Unhandled ioError,但try 语句没有捕获到错误。错误只是像没有 try 语句一样被抛出。
当然,我可以用
替换该代码this._subtitle.addEventListener(IOErrorEvent.IO_ERROR, function (ev:Event) { trace('subtitle not loaded'); });
this._subtitle = new SubtitleController(subtitlePath, _framerate);
this._subtitle.addEventListener(Event.COMPLETE, subtitleLoaded);
它几乎可以工作,它停止抛出该错误,而是抛出另一个错误。
但try-catch 块的全部意义不在于这样做吗?为什么它不能与try-catch 一起使用,但它可以与常规事件侦听器一起使用?
【问题讨论】:
-
你可能不走运,adobe 制作的动作脚本库真的很丑,多种类型的“事件处理程序”模式和异常似乎非常固定.. 异常/错误似乎经常广播事件与原始调用。
标签: flash actionscript-3 error-handling try-catch