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
code after a
block executes. In this example, the
try
ActionScript object, regardless of whether an error occurred.
var account = new Account()
try {
var returnVal = account.getAccountInfo();
if(returnVal != 0) {
throw new Error("Error getting account information.");
}
}
finally {
// Delete the 'account' object no matter what.
if(account != null) {
delete account;
}
}
The following example demonstrates a
executed. If an exception is thrown by any code within the
block, which displays the error message in a text field using the
var account = new Account()
try {
var returnVal = account.getAccountInfo();
if(returnVal != 0) {
throw new Error("Error getting account information.");
}
} catch (e) {
status_txt.text = e.toString();
}
The following example shows a
Depending on the type of error that occurred, the
object. In this case,
method can throw two different types of errors: RecordSetException and
sortRows()
MalformedRecord.
In this example, the RecordSetException and MalformedRecord objects are subclasses of the
Error class. Each is defined in its own AS class file. (For more information, see
"Creating Classes with ActionScript 2.0," on page
// In RecordSetException.as:
class RecordSetException extends Error {
var message = "Record set exception occurred."
}
// In MalformedRecord.as:
class MalformedRecord extends Error {
var message = "Malformed record exception occurred.";
}
try..catch
code block with multiple, typed
try
is an instance of a (hypothetical) class named RecordSet whose
myRecordSet
statement. Because code in the
try..finally
block is used to delete an
finally
statement. The code within the
block, control passes to the
try
Error.toString()
code block throws a different type of
try
155.)
block is
try
catch
method.
code blocks.
catch
Chapter 9,
try..catch..finally
737
Need help?
Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?
Questions and answers