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

Alternative to throwing exception in locate? #5

Open
beverlycodes opened this issue Mar 28, 2011 · 0 comments
Open

Alternative to throwing exception in locate? #5

beverlycodes opened this issue Mar 28, 2011 · 0 comments

Comments

@beverlycodes
Copy link

I'd like to propose either a change to the locate method, or creation of an alternate method. The locate method throws an exception when the operation does not find a suitable match. This seems unnecessary. In general terms, when I perform a search I expect one of two results. I either find what I'm looking for, or I don't. Neither of these is an unexpected case, but the latter is treated as such when locate throws the ElementNotFound exception.

If my own code is wrapping up locate into a more complex find strategy, having to handle "not found" exceptions adds a whole lot of extra work. If my search strategy is building an array of results, I can easily handle returns of nil or [] with methods such as Array#compact and Array#concat. Forcing me to handle ElementNotFound exceptions requires me to either introduce a rescue block, or bury ALL exceptions with a "rescue nil". Neither exception handling case is desired.

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

1 participant