开发者

Are ActionScript 3 Errors used the same way Java Exceptions are ?

My first guess is: NO. Exception in Java are here to catch 'expected' exceptions and handle them with开发者_开发技巧in the application. Error in ActionScript 3 are here to handle 'unexpected' errors. Am I right ?


Exceptions in ActionScript and Java have the same conception except the following:

  • Java has checked and unchecked exceptions. In ActionScript all the exceptions are unchecked, so you need to read API documentation or source code to handle possible exceptions which a particular method can throw. All the ActionScript exceptions which can be thrown are inherited from the Error class.
  • ActionScript in Flash Player has an asynchronous nature. This is the reason you can't handle some exceptions with a try…catch…finally block. Prior to Flash Player 10.1 there was no way to handle these exceptions. Flash Player 10.1 added global error handling with flash.events.UncaughtErrorEvent.
  • Some classes produce documented error events which have the same function as exceptions. They are inherited from flash.events.ErrorEvent and produce exceptions in case of absence of corresponding event listeners. For example, SWFLoader can fire ioError of type flash.events.IOErrorEvent which should be handled.

All the other things related to errors are similar to Java :)


Yes. While Errors in Java refer to problems outside of the scope of the normal programmer, Errors in ActionScript are handled in try...catch...finally statements, like Exceptions in Java.

See this ActionScript 2 guide and Adobe's documentation.


No Its Not like that

this is the syntax

try {
    // statements
} catch (error:ArgumentError) {
    trace('An argument error has occured');
} catch (error:Error) {
    trace('An error has occured which is not argument related');
}

we can use an argumented exceptions like IO, Custom Events too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜