From: Intransition Date: 2012-01-21T03:49:57+09:00 Subject: What defines an Error? ------=_Part_116_12498399.1327085391910 Content-Type: multipart/alternative; boundary="----=_Part_117_9859850.1327085391910" ------=_Part_117_9859850.1327085391910 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit I wonder how we are to know the appropriate error to raise or to subclass? Presently, we simply make a pretty good subjective guess. But I wonder if it could be more concrete. Might we be able to define a test for each error by which it could be determined? For example, maybe: class TypeError 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 the error and #apply! to do so. Does narrowly defining the purpose of errors this way make sense? ------=_Part_117_9859850.1327085391910 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I wonder how we are to know the appropriate error to raise or to subclass? =

Presently, we simply make a pretty good subjective guess. But I won= der if it could be more concrete. Might we be able to define a test for eac= h error by which it could be determined? For example, maybe:

 =   class TypeError

      def self.applies?(target= , criterion)
        return false unless E= xception =3D=3D=3D target
        return false = unless Exception =3D=3D=3D criterion
      &nbs= p; true
      end

      d= ef raise?(target, criterion)
        = return false unless applies?(target, criterion)
    =     return true unless criterion =3D=3D target
 &nbs= p;    end

      def self.apply!(target= , criterion)
        raise ArgumentEr= ror unless applies?(target, criterion)
      &n= bsp; raise self if raise?(target, criterion)
      end
    end

So #applies? would return false if the given argum= ents do not make any sense for the error. And we could use #raise? to see i= f it would raise the error and #apply! to do so.

Does narrowly defin= ing the purpose of errors this way make sense?

------=_Part_117_9859850.1327085391910-- ------=_Part_116_12498399.1327085391910--