I am currently writing a function returning an object from a list according to a given criteria. It looks like this:
for (Object object : list) {
if (condition(object)) {
return object;
}
}
This function should always return something from the list, and in the case no matching object was found, it was a bad call, a critical error, and the program should stop.
So, as I work with assertions enabled, I did the following just after the loop:
assert false; // Will always trigger in debug mode.
return null; // No matter anyway, an AssertionException has already been thrown.
But I wonder if I did well or not?
If not, what should I do instead? Throws an exception myself?
In any case, is there any kind of norm about this situation?