Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom error for "no patterns matched"? #64

Closed
xtuc opened this issue Mar 2, 2018 · 7 comments
Closed

Custom error for "no patterns matched"? #64

xtuc opened this issue Mar 2, 2018 · 7 comments

Comments

@xtuc
Copy link
Member

xtuc commented Mar 2, 2018

It's written in https://github.com/tc39/proposal-pattern-matching#no-fall-through:

It is a runtime error if no patterns are matched

I assume you are referring to Error. I think it would be useful to be able to differentiate runtime error thrown in the expressions from the "no patterns matched" error?

Note that throw could eventually become an expression: https://github.com/tc39/proposal-throw-expressions.

@ljharb
Copy link
Member

ljharb commented Mar 2, 2018

It’d be great to add a new error type but past precedent suggests it’ll just be a TypeError.

@xtuc
Copy link
Member Author

xtuc commented Mar 5, 2018

I'm just curious what "past precedent suggests" are you referring to?

We could make that clearer in the README as well btw.

@ljharb
Copy link
Member

ljharb commented Mar 5, 2018

Just looking at ES6+ error additions.

@c-dante
Copy link

c-dante commented Mar 17, 2018

So, UnmatchedPatternException? Or NonExhaustiveMatch? Or some new error type.

Definitely in support of this.

@masaeedu
Copy link

@xtuc Couldn't you just use the default case to produce whatever kind of expression you like if you actually anticipate values that have no matching case? This way it doesn't so much matter what the thrown error is, because it will usually only arise as a result of a programming mistake.

@xtuc
Copy link
Member Author

xtuc commented Mar 23, 2018

@masaeedu I'm just trying to clarify the spec

@zkat
Copy link
Collaborator

zkat commented Mar 25, 2018

Hey y'all! #65 has gotten merged, and a lot of issues have become irrelevant or significantly changed in context. Because of the magnitude of changes and subtle differences in things that seem similar, we've decided to just nuke all existing issues so we can start fresh. Thank you so much for the contributions and discussions and feel free to create new issues if something seems to still be relevant, and link to the original, related issue so we can have a paper trail (but have the benefit of that clean slate anyway).

I'll comment on this issue in particular, though, to say that the new spec throws a MatchError when no clauses were able to match, which I think fulfills the thing this issue was asking for, so hopefully it's resolved!

@zkat zkat closed this as completed Mar 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants