Skip to content

Alternative to throwing exception in locate? #5

@beverlycodes

Description

@beverlycodes

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions