Skip to content

Make catch clause variables optional #17467

New issue

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

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

Already on GitHub? # to your account

Closed
DanielRosenwasser opened this issue Jul 27, 2017 · 7 comments
Closed

Make catch clause variables optional #17467

DanielRosenwasser opened this issue Jul 27, 2017 · 7 comments
Labels
Committed The team has roadmapped this issue ES Next New featurers for ECMAScript (a.k.a. ESNext) Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jul 27, 2017

The proposal by @michaelficarra makes the binding identifier in catch clauses optional.

For example:

try {
    JSON.parse("...");
}
catch {
    // Don't care, the error message is completely useless,
    // but we need to handle it.
}

This proposal reached stage 3 immediately upon presentation.

@DanielRosenwasser DanielRosenwasser added ES Next New featurers for ECMAScript (a.k.a. ESNext) Suggestion An idea for TypeScript labels Jul 27, 2017
@RyanCavanaugh RyanCavanaugh added the Committed The team has roadmapped this issue label Jul 27, 2017
@RyanCavanaugh
Copy link
Member

🚲 🏠 what should we name the variable when downleveling?

@DanielRosenwasser
Copy link
Member Author

DanielRosenwasser commented Jul 27, 2017

I was thinking unexpectedTokenInJsonAtPositionError.

@jwbay
Copy link
Contributor

jwbay commented Jul 28, 2017

I'd vote 🤷‍♀️, with further downleveling as appropriate.

@saschanaz
Copy link
Contributor

The page is moved to https://tc39.github.io/proposal-optional-catch-binding/, for someone who wants to track the change of TS 2.5.

@mhegazy mhegazy added this to the TypeScript 2.5 milestone Aug 16, 2017
@ZanderBrown
Copy link

ZanderBrown commented Aug 31, 2017

Just a thought but how about having the catch block itself as optional?

For example we have the 'traditional' try catch:

try {
    // Something risky
} catch (e) {
    // Handle the specifics of e
}
// Continue

The 'I don't care what went wrong' try catch:

try {
    // Something risky
} catch {
    // ¯\_(ツ)_/¯, Something happen lets do this instead
}
// Continue

So how about a 'I don't care' try (catch):

try {
    // Something risky
}
// Continue

@kitsonk
Copy link
Contributor

kitsonk commented Aug 31, 2017

That would be a good suggestion for ESDiscuss and I am sure that TypeScript would follow suit if the proposal made it. Diverging outside of that just in TypeScript wouldn't likely make sense.

@ghost
Copy link

ghost commented Sep 7, 2017

@ZanderBrown try doesn't imply catch. Consider try...finally.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Committed The team has roadmapped this issue ES Next New featurers for ECMAScript (a.k.a. ESNext) Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

7 participants