EasyManua.ls Logo

MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE - Try..catch..finally Statement

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...
230 ActionScript language elements
try {
checkEmail("Joe Smith");
}
catch (e) {
error_txt.text = e.toString();
}
In the following example, a subclass of the Error class is thrown. The checkEmail() function
is modified to throw an instance of that subclass.
// Define Error subclass InvalidEmailError // In InvalidEmailError.as:
class InvalidEmailAddress extends Error { var message = "Invalid email
address."; }
In a FLA or AS file, enter the following ActionScript in Frame 1 of the Timeline:
import InvalidEmailAddress;
function checkEmail(email:String) {
if (email.indexOf("@") == -1) {
throw new InvalidEmailAddress();
}
}
try {
checkEmail("Joe Smith");
}
catch (e) {
this.createTextField("error_txt", this.getNextHighestDepth(), 0, 0, 100,
22);
error_txt.autoSize = true;
error_txt.text = e.toString();
}
See also
Error
try..catch..finally statement
try {
// ... try block ...
} finally {
// ... finally block ...
}
try {
// ... try block ...
} catch(error [:ErrorType1]) {
// ... catch block ...
} [catch(error[:ErrorTypeN]) {
// ... catch block ...
}] [finally {
// ... finally block ...

Table of Contents

Related product manuals