Closed valleydali closed 3 months ago
The documentation needs clarification. A catch
or finally
block is always required. Try
try { nop } catch { nop } else { echo well }
Also, the "If catch is present" item is somewhat incorrect as catch
or finally
is always required:
elvish> try { nop }
Compilation error: try must be followed by a catch block or a finally block
[tty 53]:1:1: try { nop }
elvish> try { nop } finally { put finally }
▶ finally
OK, thanks! Yes, try-catch-else
works.
Interestingly, try-finally-else
does not work... but try-else-finally
does. I guess finally
really wants to be last, which makes sense.
Whether try-finally-else
should work is debatable. Personally, I am opposed to allowing the clauses appear in every possible ordering. Why not finally-try-else
? As long as the documentation is clear I have no objection to imposing an order on the clauses.
The language specification (https://elv.sh/ref/language.html#try), section 8.9 (Exception control: Try), item 3, states:
But this does not work. I get:
Unfortunate, because this would be a useful feature if it worked.
I am using the latest release, 0.19.2.