EasyManua.ls Logo

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

MACROMEDIA FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE
780 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...
Error 361
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
String - A 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());
}

Table of Contents

Related product manuals