I wonder how we are to know the appropriate error to raise or to
Presently, we simply make a pretty good subjective guess. But I wonder
it could be more concrete. Might we be able to define a test for each
by which it could be determined? For example, maybe:
def self.applies?(target, criterion) return false unless Exception === target return false unless Exception === criterion true end def raise?(target, criterion) return false unless applies?(target, criterion) return true unless criterion == target end def self.apply!(target, criterion) raise ArgumentError unless applies?(target, criterion) raise self if raise?(target, criterion) end end
So #applies? would return false if the given arguments do not make any
sense for the error. And we could use #raise? to see if it would raise
error and #apply! to do so.
Does narrowly defining the purpose of errors this way make sense?