Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2001-03-20 19:36:59


I don't understand your assertion**The OpenClipboard docs, for example, seem
to put no restriction on which errors can be reported. That seems to
indicate that it can report out-of-memory or any number of other errors. In
addition, I would not expect any guarantee that future OS versions would
limit error returns to reporting usage errors.

-Dave

**no pun intended
----- Original Message -----
From: "Aleksey Gurtovoy" <alexy_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, March 20, 2001 5:58 PM
Subject: RE: [boost] Re: Runtime error reporting

> Jesse Jones wrote:
> > >void clipboard::put_text(std::string const& text) {
> > > HGLOBAL handle = ::GlobalAlloc( GHND, text.length() + 1 );
> > > // copy text to allocated memory
> > > // ..
> > > // copy text to clipboard
> > > bool result1 = ::OpenClipboard(0);
> > > assert(result1);
> > > bool result2 = ::EmptyClipboard();
> > > assert(result2);
> > > bool result3 = ::SetClipboardData(CF_TEXT, handle);
> > > assert(result3);
> > > bool result4 = ::CloseClipboard();
> > > assert(result4);
> > >}
> >
> > This is the problem with VERIFY: when it's there you're
> > tempted to use it. :-)
>
> Same with 'assert' :)
>
> [snip]
>
> > In the code snippet above the first three error conditions should be
> > handled with exceptions (or the moral equivalent).
>
> I disagree. Given the calling sequence, it is guaranteed that all the
calls
> will succeed if both the OS environment and your program are in consistent
> state (no leaked/invalid handles, no corrupted memory regions etc.). If
they
> are not, it's a problem of a code that put your program/OS into such
state,
> but for sure not the 'clipboard::put_text' function; assertions in that
> function only help to detect such problems early and track their sources
> more easily, but generally you better to find the real bugs instead of
> trying to live with their consequences. In any case, throwing the
exception
> here doesn't give you anything, except that it forces all clients of the
> function to wrap the 'put_text' call into try-catch block that will be
empty
> anyway.
>
>
> Aleksey
>
>
>
> List-Unsubscribe: <mailto:boost-unsubscribe_at_[hidden]>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>


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