Pattern for error checking easiest-first?

Discussion in 'Python' started by jquinn+google@cs.oberlin.edu, Aug 20, 2007.

  1. Guest

    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?
    , Aug 20, 2007
    #1
    1. Advertising

  2. On 20 ago, 18:01, wrote:

    > 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?


    What about this:

    class AbstractThing():
    def changeMe(self,blah):
    self.verify_blah(blah)
    self.blah = blah

    def verify_blah(self, blah):
    if blah < 1:
    raise MyException

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

    That is, it's the verify step that is overriden/enhanced, not the
    changeMe method that stays the same.

    --
    Gabriel Genellina
    Gabriel Genellina, Aug 21, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QmlsbCBCb3Jn?=

    Easiest way to get page name from error routine?

    =?Utf-8?B?QmlsbCBCb3Jn?=, Mar 2, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    436
    Tommy
    Mar 3, 2004
  2. Replies:
    17
    Views:
    1,843
    Chris Uppal
    Nov 16, 2005
  3. sunny
    Replies:
    1
    Views:
    451
    Salt_Peter
    Dec 7, 2006
  4. Replies:
    10
    Views:
    189
    Anno Siegel
    Feb 9, 2006
  5. leohan
    Replies:
    4
    Views:
    127
    Tad McClellan
    Apr 7, 2006
Loading...

Share This Page