Boost logo

Boost :

From: Jesse Jones (jejones_at_[hidden])
Date: 2001-03-20 19:09:43

>Gary Powell 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
>> > sys_verify(::OpenClipboard(0));
>> > sys_verify(::EmptyClipboard());
>> > sys_verify(::SetClipboardData(CF_TEXT, handle));
>> > sys_verify(::CloseClipboard());
>> > }
>Well, ignoring the 'GlobalAlloc' call, the only situation when
>'clipboard::put_text' may fail is when something else in another part of
>your program went wrong, e.g. you forgot to close clipboard handle in some
>other place, your clipboard handle for some reason become invalid between
>API calls, etc., i.e. failure of a API call here is only an indication of a
>programmer's error(s) somewhere else in the system (and failure or
>successful execution of the function does not in any way depend on its input
>parameters), so IMO that's exactly what assertions are for.

If all of this code was your own code you might be able to make this
argument because you're testing the code as a unit and you'll see if your
assumptions hold up. But you're dealing directly with the OS so there's no
way you can arrange to have a debug build run on every version of the OS
and every configuration your customers may have. So, unless the OS provides
stronger guarantess than is typical I don't think assertions are wise here.

  -- Jesse

Boost list run by bdawes at, gregod at, cpdaniel at, john at