37 lines
866 B
Plaintext
37 lines
866 B
Plaintext
print("\n--- Test: try/catch with loops ---");
|
|
|
|
// Break and continue in finally
|
|
var i = 0; var seq = [];
|
|
while (true) {
|
|
try {
|
|
i = i + 1;
|
|
seq.push(i);
|
|
if (i == 1) {}
|
|
}
|
|
finally {
|
|
if (i < 2) continue;
|
|
break;
|
|
}
|
|
}
|
|
assert(i == 2 && seq.len() == 2, "continue/break in finally");
|
|
|
|
// Throw in loop body caught and handled without extra reporter noise
|
|
var hits = [];
|
|
for (var j = 0; j < 3; j = j + 1) {
|
|
try {
|
|
if (j == 1) throw {"message":"bang"};
|
|
hits.push(j);
|
|
} catch (e) {
|
|
hits.push("caught:" + e.message);
|
|
}
|
|
}
|
|
// Strictly check sequence; avoid out-of-bounds checks
|
|
assert(hits.len() == 3, "loop catch sequence length");
|
|
assert(hits[0] == 0, "loop catch sequence item0");
|
|
assert(hits[1] == "caught:bang", "loop catch sequence item1");
|
|
assert(hits[2] == 2, "loop catch sequence item2");
|
|
|
|
print("try/catch with loops: PASS");
|
|
|
|
|