36
finallyDone = false;
try {
x = 1;
if (action === 'fail') {
throw action;
} else if (action === 'return') {
return;
}
x = 2;
} catch (e) {
// Executed if a throw statement is executed.
assertEqual(1, x);
caught = e;
} finally {
// Executed regardless of whether or not a throw statement is
// executed. Also executed if a return statement causes the
// function to exit before the end of the try block.
finallyDone = true;
}
}
f('fail');
assertEqual(1, x);
assertEqual('fail', caught);
assert(finallyDone);
f('return');
assertEqual(1, x);
assert(!caught);
assert(finallyDone);
f();
assertEqual(2, x);
assert(!caught);
assert(finallyDone);
}
// Run tests
References();
Operators();
OuterFunction();
Loops();
Exceptions();
function assertEqual(expected, actual) {
if (expected !== actual) {
throw 'expected: ' + ex ', actual: ' + actual;
}
}
function assert(condition) {
if (!condition) {
throw 'failed assertion';
}
}
Coaxlink
Programmer Guide
6. Euresys GenApi scripts