Tostring (Error.tostring Method) - MACROMEDIA FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE Reference

Flash lite 2.x actionscript language reference
Hide thumbs Also See for FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE:
Table of Contents

Advertisement

var theNum:Number = divideNumber(1, 0);
trace("SUCCESS! "+theNum);
// output: DivideByZeroError -> Unable to divide by zero.
} catch (e_err:DivideByZeroError) {
// divide by zero error occurred
trace(e_err.name+" -> "+e_err.toString());
} catch (e_err:Error) {
// generic error occurred
trace(e_err.name+" -> "+e_err.toString());
}
To add a custom error, add the following code to a .AS file called DivideByZeroError.as and
save the class file in the same directory as your FLA document.
class DivideByZeroError extends Error {
var name:String = "DivideByZeroError";
var message:String = "Unable to divide by zero.";
}
See also
,
throw statement
try..catch..finally statement

toString (Error.toString method)

public toString() : String
Returns the string "Error" by default or the value contained in Error.message, if defined.
Availability: ActionScript 1.0; Flash Lite 2.0
Returns
- A String
String
Example
In the following example, a function throws an error (with a specified message) if the two
strings that are passed to it are not identical:
function compareStrings(str1_str:String, str2_str:String):Void {
if (str1_str != str2_str) {
throw new Error("Strings do not match.");
}
}
try {
compareStrings("Dog", "dog");
// output: Strings do not match.
} catch (e_err:Error) {
trace(e_err.toString());
}
Error
361

Advertisement

Table of Contents
loading

Table of Contents