bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Common C++ persistence engine and exceptions


From: David Sugar
Subject: Re: Common C++ persistence engine and exceptions
Date: Mon, 12 Aug 2002 09:59:03 -0400
User-agent: KMail/1.4.1

I think that is a valid point.  The persistence engine, while it has been 
experimental code for a long time, it also has been very stable and hasn't 
been changed very much.  If you would like to make a patch for doing this, I 
would be happy to take it in.

On Monday 12 August 2002 08:43, Pierre Bacquet wrote:
> Hello,
>
> I've retrieved the last pre-2 versions (0.99.7 I think) and I've found
> that
> the persistence engine uses assert in some places.
>
> Though the following:
>
> void Engine::write(const std::string& str) THROWS (Engine::Exception)
> {
>   assert(myOperationalMode == modeWrite);
>  ...
>
> or
>
> void Engine::read(std::string& str) THROWS (Engine::Exception)
> {
>   assert(myOperationalMode == modeRead);
>   ...
>
> may make sense (this is a kind of programmation error that shouldn't
> happen during runtime)
>
> I think that assert like :
>
>   // Create the object (of the relevant type)
>   object = TypeManager::createInstanceOf(className.c_str());
>   if (object)
>  {
>    // Okay then - we can make this object
>    myArchiveVector.push_back(object);
>    std::string majik;
>    read(majik);
>    assert(majik == string("OBST"));
>    object->read(*this);
>    read(majik);
>    assert(majik == string("OBEN"));
>  }
>   else
>    THROW (Exception((std::string("Unable to instantiate object of class
> ")+className).c_str()));
>
> could be replaced by exceptions in order to be handled, if needed, by
> the calling program.
> These kinds of problems (OBject STart and OBject ENd markers not found)
> are likely to happen
> if you read a persistence file produced by another program. So, this
> kind of error is likely to
> happen in regular run-time (i.e. not during development).
>
> So, one may think about using :
>
> if (object)
>  {
>    // Okay then - we can make this object
>    myArchiveVector.push_back(object);
>    std::string majik;
>    read(majik);
>    if (majik != string("OBST"))
>      THROW (Exception((std::string("OBST not found
> ")+className).c_str()));
>   object->read(*this);
>    read(majik);
>    if (majik != string("OBEN"));
>      THROW (Exception((std::string("OBEN not found
> ")+className).c_str()));
>  }
>   else
>    THROW (Exception((std::string("Unable to instantiate object of class
> ")+className).c_str()));
>
> One may even think about displaying also the file position (
> Engine::myUnderlyingStream.tellg() )
> to help people understanding where things may have gone wrong.
>
> What do you think of that ?
>
> Greetings,
>
> Pierre Bacquet.
>
>
>
> _______________________________________________
> Bug-commoncpp mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/bug-commoncpp





reply via email to

[Prev in Thread] Current Thread [Next in Thread]