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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With