Pattern for error checking easiest-first?

jquinn+google at cs.oberlin.edu jquinn+google at cs.oberlin.edu
Mon Aug 20 17:01:59 EDT 2007


Heres the situation:

class AbstractThing():
    def changeMe(self,blah):
         if blah < 1:
              raise MyException
         self.blah = blah

class NetworkedThing(AbstractThing):
    def changeMe(self,blah):
        if blah > self.getUpperLimitOverTheNetworkSlowly:
             raise MyOtherException
        AbstractThing.changeMe(self,blah)


The problem is that code like this does error checking backwards. A
call to NetworkedThing.changeMe will first do a slow error check and
then a fast one. Obviously there are various ways to get around this -
either have the subclass explicitly ask the superclass to error check
first, or vice totally versa. Is there some accepted pattern/idiom for
handling this issue?




More information about the Python-list mailing list