摘自:http://www.darronschall.com/weblog/archives/000076.cfm
try {
someConverstionFunction(string);
} catch (an IllegalArgumentException) {
} catch (a NumberFormatException) {
} catch (some other Exception) {
}
///////////////////////////////////////////////////////////
IllegalArgumentException.as
class IllegalArgumentException extends Error {
public function IllegalArgumentException () {
super.constructor.apply(this, arguments);
}
}
//////////////////////////////////////
function onlyAllow1Param(param) {
if (arguments.length > 1) {
throw new IllegalArgumentException("Only 1 param allowed");
}
if (param == "cow") {
throw new Error("No cows allowed here");
}
}
try {
onlyAllow1Param("one", "two");
} catch (iae:IllegalArgumentException) {
trace("IllegalArgumentException caught: " + iae);
} catch (e:Error) {
trace("Error caught: " + e);
} finally {
trace("Finally block executed");
}
///////////////////////////////////////////
try {
throw "this is an error";
} catch (e:Error) {
trace("Error caught. e instanceof Error = " + (e instanceof Error));
trace(typeof(e));
}