Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionScript 3.0 try..catch

If I use

try{
    function1();
    function2();
    function3();
}
catch(e:Error){
    function4();
}

and let's say in function2() an exception is thrown, which of the code does get executed by definition? will function3() get executed? will the effects of function1 be present after the catch? (there are programming languages that 'rewind' the effects such as if the whole block wasn't executed)

thanks for clarification!

like image 656
Mat Avatar asked Jun 14 '11 14:06

Mat


1 Answers

A try catch will execute all code UNTIL an exception is thrown. At that point, the exception will bubble until it either hits a catch block or the program exits. Flash does not "rewind" any code it has executed.

Say function2() is 10 lines and line 4 throws the exception, lines 5-10 will not be executed. Nor will function3(). The code will go into your catch and then execute function4().

Another construct for use in try..catch.. is the finally block, which is a section of code that gets executed after the try or catch. It is particually useful for things like myNetConn = null where you may have had an error closing a NetConnection, but still wish to null the object.

like image 69
Ben Roux Avatar answered Oct 06 '22 01:10

Ben Roux