Naming not unique result error in python?
Maybe this is a little unconventional question but I'd like to hear an answer to it. Since english is not my native language I thought I'd ask for a second opinion.
I want to raise an Error in python and was wondering how to name it.
class AmbiguousResultError(Exception): pass
cla开发者_开发技巧ss NoResultFoundError(Exception): pass
def getUrlFor(mystring):
list_of_urls = []
# parse url object for all matching urls for the given string
# and add them to list_of_urls
if len(url) > 1:
raise AmbiguousResultError("More then one url matches for {0}".format(mystring))
elif not url:
raise NoResultFoundError("There was no matching url for {0}".format(mystring))
else:
return list_of_urls[0]
The first raise
is the one which I was wondering, how to name it such that it is precise. I thought of
NoUniqueResultFoundError
AmbiguousResultError
UncertainResultError
But they all don't satisfy me, and I don't know if I hit the nail with this nameing. It should be obvious to others, too. There has to be a specific expression for that. Which one is it. I thought of asking it on english.stackexchange.com, but I think a programmer has another sort of thinking then a philologist.
I'd prefer AmbiguousStringError
to AmbiguousResultError
. After all, it's not the result that has multiple meanings, it's the string the user provided.
Or possibly MultipleResultsFoundError
. I think your suggestion of NoUniqueResultFoundError
is as good as anything though. If you're as thorough and thoughtful with the rest of your code as you are with this, other developers won't have a problem debugging it.
精彩评论