Skip to content

RFC: Error Matching Syntax #3

Description

@JamesDHW

RFC: Error Matching Syntax

Currently, this will not be added as a part of ErrorScript, to reduce the implementation overhead, prevent disagreements on this topic delaying implementation of ErrorScript.

Despite that, it's worth discussing the options due to the nice devX provided by built-in error matching.

Options

  1. No new syntax (use existing TypeScript narrowing)

    • Match errors using instanceof, typeof, equality checks, user-defined type guards, and assertion functions.
  2. Multi-catch / typed binding syntax

    • Examples (illustrative): catch (NetworkError as e), catch (NetworkError | StorageError as e)
  3. Pattern matching / conditional catch

    • Examples (illustrative): catch (e) when isNetworkError(e), catch case NetworkError(e) => ...
  4. Exhaustive catch constructs

    • New syntax that implies or enforces exhaustiveness and default rethrow behavior.
  5. Type-binding:

    • Syntax: catch (e: NetworkError)

Decision: if this is to be implemented at all, I propose option 2 catch (NetworkError as e)

Why: it's clean, with minimal reading, doesn't overlap with existing syntax.

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions