Boost logo

Boost Users :

From: James Dennett (jdennett_at_[hidden])
Date: 2007-01-07 16:56:38


Robert Ramey wrote:
> James Dennett wrote:
>
>> Is there an explicit way to flush the archive before
>> reaching its destructor? Presumably writing output
>> to a stream can cause an exception to be thrown, and
>> we would want to be able to handle such errors rather
>> than hitting terminate().
>>
>> -- James
>
> There isn't. I'm not sure there should be. It's
> only needed for xml archives but adding it would
> require that it be put in all the other archives as
> a no-op.

Indeed; that's often the cost of polymorphically
supporting a wider range of behaviors.

> Also "flush" suggests that one could continue using the
> archive after it was "flushed" like a stream. This
> would not be case as the function of "flush" would be
> to finish off the xml data structure.

Fair comment; flush wasn't a suggested name. A better
name would be "close".

> Ideally what I would like to do is throw an exception in the
> archive destructor if the stream is still open - but that's not
> a good idea.

Right, that's the crux of the issues; destructors that
do things that can throw are highly problematic, which
is an argument for allowing everything that might throw
to be moved out of a destructor. Most destructors
really ought just to destroy things and release
resources; if a destructor does something that can
fail, there ought to be a way to try to do that from
a named function so that the error can be handled as
well as possible.

-- James


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net