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:
- Union syntax:
try[ValueError | TypeError] foo() — consistent with Python's except (ValueError, TypeError)
- Tuple syntax:
try[ValueError, TypeError] foo() — more compact
- 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
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:
try[ValueError | TypeError] foo()— consistent with Python'sexcept (ValueError, TypeError)try[ValueError, TypeError] foo()— more compactConsiderations:
exceptclause syntax in try statementsResulttype if try expression returnsResult[T, E]References
docs/language_specification/error_handling.md— try expression specificationdocs/language_specification/expressions.md— expression syntax