Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try {...} else {...} is documented but doesn't work #1734

Closed
valleydali opened this issue Nov 26, 2023 · 3 comments · Fixed by #1782
Closed

try {...} else {...} is documented but doesn't work #1734

valleydali opened this issue Nov 26, 2023 · 3 comments · Fixed by #1782

Comments

@valleydali
Copy link

The language specification (https://elv.sh/ref/language.html#try), section 8.9 (Exception control: Try), item 3, states:

  1. If no exception occurs and else is present, else-block is executed. Example:
~> try { nop } else { echo well }
well

But this does not work. I get:

% try { nop } else { echo well }
Compilation error: try must be followed by a catch block or a finally block
  [tty 8]:1:1: try { nop } else { echo well }

Unfortunate, because this would be a useful feature if it worked.

I am using the latest release, 0.19.2.

@krader1961
Copy link
Contributor

krader1961 commented Nov 26, 2023

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

@valleydali
Copy link
Author

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.

@krader1961
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants