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

Error vs sentinel #23

Open
jtrakk opened this issue Mar 25, 2021 · 2 comments
Open

Error vs sentinel #23

jtrakk opened this issue Mar 25, 2021 · 2 comments

Comments

@jtrakk
Copy link

jtrakk commented Mar 25, 2021

Sometimes people say that exceptions should only be raised for unexpected states in the program, but that a nonmatching parse is often an expected state so it should just return a sentinel value instead of raising an error. What do you think?

@gkappler
Copy link
Owner

I agree. The parse method throws an error to match behaviour of Base.parse(Int,"abc"). Please refer to tryparse instead, that returns nothing if there is no match.

Yet your question makes me wonder whether instead returning NoMatch() singleton would be clearer as nothing might be a intended parsing result. What do you think?

@jtrakk
Copy link
Author

jtrakk commented Mar 25, 2021

I agree returning NoMatch() would be less ambiguous in cases where nothing is a valid parse result. I suppose theoretically NoMatch() could be an intended parsing result, in which case tryparse could take a sentinel argument.

gkappler added a commit that referenced this issue Sep 30, 2022
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

2 participants