03.05.2013 Views

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Parameters<br />

message:String [optional] - A string associated with the Error object.<br />

Example<br />

In the following example, a function throws an error (with a specified message) if the two<br />

strings that are passed to it are not identical:<br />

function compareStrings(str1_str:String, str2_str:String):Void {<br />

if (str1_str != str2_str) {<br />

throw new Error("Strings do not match.");<br />

}<br />

}<br />

try {<br />

compareStrings("Dog", "dog");<br />

// output: Strings do not match.<br />

} catch (e_err:Error) {<br />

trace(e_err.toString());<br />

}<br />

See also<br />

throw statement, try..catch..finally statement<br />

message (Error.message property)<br />

public message : String<br />

Contains the message associated with the Error object. By default, the value of this property is<br />

"Error". You can specify a message property when you create an Error object by passing the<br />

error string to the Error constructor function.<br />

Availability: <strong>ActionScript</strong> 1.0; Flash Player 7<br />

Example<br />

In the following example, a function throws a specified message depending on the parameters<br />

entered into theNum. If two numbers can be divided, SUCCESS <strong>and</strong> the number are shown.<br />

Specific errors are shown if you try to divide by 0 or enter only 1 parameter:<br />

function divideNum(num1:Number, num2:Number):Number {<br />

if (isNaN(num1) || isNaN(num2)) {<br />

throw new Error("divideNum function requires two numeric parameters.");<br />

} else if (num2 == 0) {<br />

throw new Error("cannot divide by zero.");<br />

}<br />

return num1/num2;<br />

554 <strong>ActionScript</strong> classes

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!