-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Begin drafting try/catch proposal #2850
base: main
Are you sure you want to change the base?
Conversation
Hey everyone, I've not been involved lately, but I hope you don't mind me swooping in and giving my thoughts on this proposal. I've always wanted to see The idea of catching a I have some questions about how
There's a use case around deciding that an error isn't the one you want to handle and rethrowing it. Given that an error message may have error specific values interpolated into the message that could be kind of tricky. What do you think about the idea of augmenting When rethrowing an error, I think we'll want to preserve the original source location of the error. I think that might necessitate making a new data type. If the main use case for using |
  '}' '@catch' exceptionVar? '{' | ||
  CatchStatements | ||
  '}' | ||
**exceptionVar** ::= '$' Identifier |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two nits:
-
Production names should be capitalized (
ExceptionVar
notexceptionVar
). -
Add a comment below explaining that no whitespace is allowed between
'$'
andIdentifier
. Or better yet, editvariables.md
to have aPlainVariable
that can be re-used without having to rewrite that caveat all over the place 😆.
* Let `exception` be a map with the same identifier as `exceptionVar`, | ||
a 'name' `throw`s at-rule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having a lot of trouble understanding this sentence.
|
||
This proposal defines a pair of new at-rule directives that must be used | ||
together as a form of control. The `@try { ... } @catch { ... }` syntax captures | ||
any thrown output (error or warning messages) from inside the `@try` block, and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that catching warnings with this is unexpected. It's not how other programming languages work, and it may do very unexpected things with the control flow.
I'd like to punt on the question of how warnings are tested for now. It's much easier and safer to devise custom warning-capturing infrastructure, since you can just add strings to a list and you don't have to worry about globally coordinating return values.
Based on #2619
Rough syntax (with the unit-testing use-case):