Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #5801

Re: ORM: when to raise an exception: on object creation or on use?

From Victor Porton <porton@narod.ru>
Newsgroups comp.programming
Subject Re: ORM: when to raise an exception: on object creation or on use?
Date 2015-09-04 19:22 +0300
Organization Aioe.org NNTP Server
Message-ID <mscgfu$csi$1@speranza.aioe.org> (permalink)
References <msc92o$peq$1@speranza.aioe.org> <12w5k0sn9jcje$.fgxuw9zqjtxy$.dlg@40tude.net>

Show all headers | View raw


Dmitry A. Kazakov wrote:

> On Fri, 04 Sep 2015 17:15:53 +0300, Victor Porton wrote:
> 
>> Should an ORM implementation query the DB as soon as an active record is
>> created in order to check that the queried row exists in DB, or is it OK
>> to throw an exception later when attempting to access a field (for an
>> nonexistent row)?
> 
> The rule is simple, only valid objects shall exist. If an object is to
> reference only an existing row, then you cannot create one that does not
> do that.
> 
> Another SW design rule is that an error has to be detected as early as
> possible. If an invalid reference is an error then...

Got your answer.

I am going to follow your advice, taking into account however that this way 
an otherwise unnecessary query to the DB is done, what makes the code less 
efficient in terms of speed and server load.

Dmitry, do you confirm that the exception should be thrown as soon as 
possible, even if this requires querying of otherwise unnecessary DB fields?

-- 
Victor Porton - http://portonvictor.org

Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

ORM: when to raise an exception: on object creation or on use? Victor Porton <porton@narod.ru> - 2015-09-04 17:15 +0300
  Re: ORM: when to raise an exception: on object creation or on use? "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2015-09-04 17:51 +0200
    Re: ORM: when to raise an exception: on object creation or on use? Victor Porton <porton@narod.ru> - 2015-09-04 19:22 +0300
      Re: ORM: when to raise an exception: on object creation or on use? "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2015-09-04 18:54 +0200
        Re: ORM: when to raise an exception: on object creation or on use? Victor Porton <porton@narod.ru> - 2015-09-04 21:17 +0300
          Re: ORM: when to raise an exception: on object creation or on use? "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2015-09-04 20:38 +0200

csiph-web