-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Optional Catch Binding (Stage 4) #7
Comments
J/k you should do it now :) |
Nah, this proposal's just going to glide right through to stage 4 as-is. Send in your PRs! |
Hi, I'd be quite happy to work on this :) |
@MarckK good news 👍 . Don't hesitate to ping us on Slack if you need help. |
What do you think of making the |
just See https://twitter.com/ljharb/status/861992651423227904 for a related thread. |
Yes, seems like the thread supported it. It's useful in cases like the following: const safeParseJson = (str) => {
try {
return JSON.parse(str);
} catch (e) {}
} When you actually wanted const safeParseJson = str => do try { JSON.parse(str) }; |
babel/babylon#634 is merged, will do a release so the transform can use it |
babel/babel#5956 (comment) has also been merged |
Released in https://github.com/babel/babel/releases/tag/v7.0.0-alpha.17 via Inputtry {
throw 0;
} catch {
console.log("it failed, but this code executes");
} Outputtry {
throw 0;
} catch (_unused) {
console.log("it failed, but this code executes");
} |
@MarckK: Want to submit a change to |
@existentialism did this in babel/babel#6032 (Stage 3) Can add to the readme now though. When should we close (was thinking when its Stage 4) |
Sorry if a little bit out of context but the comment by @reaktivo looks really appealing to me. Maybe this transform wouldn't be needed at all then because not catching errors is a bad practice anyway but if there is the case then maybe it's better to do it differently. Maybe something like
or
Currently this is a big PITA of using exception because there are no guard statements that we could easily use to try or bail. So what I see is we get a bunch of The other malice practice is people simply wrap all kind of code into one huge try+catch and do everything inside of the try block which is not optimal esp. given that error handling in Javascript is quite infantile. |
Optional catch binding is stage 3; this transform is needed regardedless. |
Hi, would you think about try..finally syntax? In react-dom there is such usage. If you can handle it, you could make react-dom runnable in Edge and old IE. // input
try{
doSomeThing();
}finally{
cleanUp();
} // output
try{
doSomeThing();
}catch(e){
}finally{
cleanUp();
} |
@licg9999 |
Oh, sorry for my misunderstanding... Error in my case is promise.finally not found, I mistook. Thanks for your warm hint. |
Champion: @michaelficarra
Spec repo: https://github.com/michaelficarra/optional-catch-binding-proposal/
Spec text: https://michaelficarra.github.io/optional-catch-binding-proposal/
Stage: -1 :)
This hasn't been presented to the committee as of this writing, but will be at the July meeting. If it receives broad support it is likely to advance quickly, in my personal estimation.
It allows the binding to be omitted from a
catch
clause:or
This will need a (very small) change in Babylon, including a change to the AST (marking the catch binding as optional), and then a very small change to Babel.
This would make a great first contribution, I think!
UPDATE:
The text was updated successfully, but these errors were encountered: