...
Note that if <block>
is not enclosed by curly braces, these have to added, as we add a second statement to the loop body.
try... catch... finally
While JavaScript supports try
... catch
... finally
statements, it (naturally) does not support multiple catch
clauses, using different error types, like so:
ActionScript:
Code Block |
---|
try {
...
} catch (e1:ArgumentError) {
// handle argument errors
} catch (e2:TypeError) {
// handle type errors
}
|
Note that a catch clause implicitly declares its variable, scoped to the catch body only. The variables could have the same name and would not clash.
The AS3 semantics is that if the error is an ArgumentError
, the first catch body is executed, if the error is a TypeError
, the second catch body is executed, and on any other error, the error is not caught at all.
Thus, the corresponding JavaScript code needs to check the runtime type of the error variable:
JavaScript:
Code Block |
---|
try {
...
} catch (e) {
if (is(e, ArgumentError)) {
var e1 = e;
// handle argument errors
} else if (is(e, TypeError)) {
var e2 = e;
// handle type errors
} else {
throw e;
}
}
|
Note that in case no type check matches, the error has to be re-thrown! This code can be omitted if the original code contains a catch
clause with an untyped or *
typed error variable.TODO
Operators
TODO
&&=
TODO
||=
TODO