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

ER: parsing of try ... catch ... #1608

Open
pkoppstein opened this issue Feb 28, 2018 · 3 comments
Open

ER: parsing of try ... catch ... #1608

pkoppstein opened this issue Feb 28, 2018 · 3 comments

Comments

@pkoppstein
Copy link
Contributor

Some users are surprised by the failure of expressions such as:

jq 'try .data |= fromjson catch "STRING"'

Here, parentheses are required around the "TRY" clause. That's a bit surprising since jq is so good about using keywords in the case of if ... then ... else ... end, and perhaps also because |= is just a binary operator.

@nicowilliams
Copy link
Contributor

I've been annoyed by this too. I think an end keyword would have made it easier for bison to disambiguate.

@nicowilliams
Copy link
Contributor

I'm partial to obsoleting try ... catch ... and replacing it with try(exp; handler) as a special builtin function.

nicowilliams added a commit to nicowilliams/jq that referenced this issue Dec 29, 2019
We can't really fix the issues with try-catch syntax, but we can
introduce `try` as a function-like syntax, using `try(exp; handler)`
in preference to `(try exp catch (handler))`.

While we're at it, we can use the new `UNWINDING` opcode to implement
try-catch-finally as `try(exp; handler; finally)`.
@nicowilliams
Copy link
Contributor

nicowilliams commented Dec 29, 2019

I've got a commit cbe4b81 that introduces try(exp; handler) and try(exp; handler; finally) syntax, leaves the old try exp catch handler syntax, and changes the manual to a) use the new syntax, b) indicate that the old syntax is obsolete and may be removed.

As for try(exp), as it happens that was already legal because try exp was legal.

nicowilliams added a commit to nicowilliams/jq that referenced this issue Dec 30, 2019
We can't really fix the issues with try-catch syntax, but we can
introduce `try` as a function-like syntax, using `try(exp; handler)`
in preference to `(try exp catch (handler))`.

While we're at it, we can use the new `UNWINDING` opcode to implement
try-catch-finally as `try(exp; handler; finally)`.
nicowilliams added a commit that referenced this issue Jan 2, 2020
We can't really fix the issues with try-catch syntax, but we can
introduce `try` as a function-like syntax, using `try(exp; handler)`
in preference to `(try exp catch (handler))`.

While we're at it, we can use the new `UNWINDING` opcode to implement
try-catch-finally as `try(exp; handler; finally)`.
nicowilliams added a commit to nicowilliams/jq that referenced this issue Jan 3, 2020
We can't really fix the issues with try-catch syntax, but we can
introduce `try` as a function-like syntax, using `try(exp; handler)`
in preference to `(try exp catch (handler))`.

While we're at it, we can use the new `UNWINDING` opcode to implement
try-catch-finally as `try(exp; handler; finally)`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants