EasyManua.ls Logo

MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE - Page 233

MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE
1378 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Statements 233
var returnVal = account.getAccountInfo();
if (returnVal != 0) {
throw new Error("Error getting account information.");
}
trace("success");
}
catch (e) {
this.createTextField("status_txt", this.getNextHighestDepth(), 0, 0, 100,
22);
status_txt.autoSize = true;
status_txt.text = e.toString();
}
The following example shows a try code block with multiple, typed catch code blocks.
Depending on the type of error that occurred, the
try code block throws a different type of
object. In this case,
myRecordSet is an instance of a (hypothetical) class named RecordSet
whose
sortRows() method can throw two types of errors, RecordSetException and
MalformedRecord.
In the following example, the RecordSetException and MalformedRecord objects are
subclasses of the Error class. Each is defined in its own AS class file.
// 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.";
}
Within the RecordSet class's sortRows() method, one of these previously defined error
objects is thrown, depending on the type of exception that occurred. The following example
shows how this code might look:
class RecordSet {
function sortRows() {
var returnVal:Number = randomNum();
if (returnVal == 1) {
throw new RecordSetException();
}
else if (returnVal == 2) {
throw new MalformedRecord();
}
}
function randomNum():Number {
return Math.round(Math.random() * 10) % 3;
}
}

Table of Contents

Related product manuals