Boost logo

Boost :

Subject: Re: [boost] [exception] ostringstream like
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-10-19 14:56:17


[I just noticed this in my drafts folder.]

Fabien Castan wrote:
>
> > No, I mean that if you do advanced string manipulation in
> > the exception
> > itself, you may screw up, adn cause a bad_alloc beign
> > thrown and masking your own exception.
>
> Create an error sentence with some values inside is not really an
> advanced string manipulation.

The proposed message construction may not involve advanced string manipulation, by some definition of "advanced," but what you propose is non-trivial and involves a good deal of free store (de)allocation. It is far better to store state that can be used to produce an error message at the point the message is wanted. Otherwise, the risk is of doing work to produce a message that may not be needed, while adding the risk of exhausting memory.

Adding an insertion operator is likely to make formatting messages too easy in contexts where code should be concerned with simply storing state for consumption elsewhere. Thus, it would encourage bad practice.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk