Skip to content

Make catch clause variables optional #17467

Description

The proposal by Michael Ficarra (@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.

Activity

  1. RyanCavanaugh commented on Jul 27, 2017

    @RyanCavanaugh
    Member

    🚲 🏠 what should we name the variable when downleveling?

  2. DanielRosenwasser commented on Jul 27, 2017

    @DanielRosenwasser
    MemberAuthor

    I was thinking unexpectedTokenInJsonAtPositionError.

  3. jwbay commented on Jul 28, 2017

    @jwbay
    Contributor

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

  4. saschanaz commented on Aug 14, 2017

    @saschanaz
    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.

  5. ZanderBrown commented on Aug 31, 2017

    @ZanderBrown

    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
  6. kitsonk commented on Aug 31, 2017

    @kitsonk
    Contributor

    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.

  7. locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CommittedThe team has roadmapped this issueES NextNew featurers for ECMAScript (a.k.a. ESNext)FixedA PR has been merged for this issueSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions