If an error is thrown within a function, and the function does not include a
the ActionScript interpreter exits that function, as well as any caller functions, until a
is found. During this process,
Example
The following example shows how to create a
block is guaranteed to execute, it is typically used to perform any necessary clean-up
finally
after a
block executes. In the following example,
try
millisecond (1 second). If an error occurs, an error is thrown and is caught by the
The finally block is always executed whether or not an error occurs. Because
used,
clearInterval()
cleared from memory.
myFunction = function () {
trace("this is myFunction");
};
try {
myInterval = setInterval(this, "myFunction", 1000);
throw new Error("my error");
} catch (myError:Error) {
trace("error caught: "+myError);
} finally {
clearInterval(myInterval);
trace("error is cleared");
}
In the following example, the
whether an error occurred. Create a new AS file called Account.as.
class Account {
var balance:Number = 1000;
function getAccountInfo():Number {
return (Math.round(Math.random()*10)%2);
}
}
In the same directory as Account.as, create a new AS or FLA document and enter the following
ActionScript in Frame 1 of the Timeline:
import Account;
var account:Account = new Account();
try {
var returnVal = account.getAccountInfo();
if (returnVal != 0) {
throw new Error("Error getting account information.");
}
} finally {
if (account != null) {
delete account;
}
}
handlers are called at all levels.
finally
try..finally
must be placed in the
block is used to delete an ActionScript object, regardless of
finally
statement. Because code in the
setInterval()
block to ensure that the interval is
finally
handler, then
catch
block
catch
calls a function every 1000
block.
catch
setInterval()
try..catch..finally
is
985
Need help?
Do you have a question about the FLASH MX 2004-ACTIONSCRIPT LANGUAGE and is the answer not in the manual?
Questions and answers