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
-
No new syntax (use existing TypeScript narrowing)
- Match errors using
instanceof, typeof, equality checks, user-defined type guards, and assertion functions.
-
Multi-catch / typed binding syntax
- Examples (illustrative):
catch (NetworkError as e), catch (NetworkError | StorageError as e)
-
Pattern matching / conditional catch
- Examples (illustrative):
catch (e) when isNetworkError(e), catch case NetworkError(e) => ...
-
Exhaustive catch constructs
- New syntax that implies or enforces exhaustiveness and default rethrow behavior.
-
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.
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
No new syntax (use existing TypeScript narrowing)
instanceof,typeof, equality checks, user-defined type guards, and assertion functions.Multi-catch / typed binding syntax
catch (NetworkError as e),catch (NetworkError | StorageError as e)Pattern matching / conditional catch
catch (e) when isNetworkError(e),catch case NetworkError(e) => ...Exhaustive catch constructs
Type-binding:
catch (e: NetworkError)