Skip to content

RFC: Syntax for combining exception types in try expressions #424

@antonsynd

Description

@antonsynd

Context

Identified during spec-test alignment audit (AMB-6). Try expressions currently support a single exception type, but there is no syntax for specifying multiple exception types.

Current behavior

Try expressions use the syntax try[ExceptionType] expression, which allows catching a single exception type. There is no way to specify multiple exception types in a single try expression.

Expected/proposed

Design a syntax for combining multiple exception types in try expressions. Options:

  1. Union syntax: try[ValueError | TypeError] foo() — consistent with Python's except (ValueError, TypeError)
  2. Tuple syntax: try[ValueError, TypeError] foo() — more compact
  3. Base class only: Require users to catch a common base class — simplest but least flexible

Considerations:

  • Should be consistent with the except clause syntax in try statements
  • Need to define what the resulting type is when different exception types are caught
  • Consider interaction with the Result type if try expression returns Result[T, E]

References

  • docs/language_specification/error_handling.md — try expression specification
  • docs/language_specification/expressions.md — expression syntax

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