|
Boost : |
From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 2001-03-20 17:03:23
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());
> > }
[snip]
> IMO this sort of API cries out for exceptions.
>
> void foo ()
> {
> try {
> put_text(TextString);
> }
> catch (TextErrors &terr)
> {
> // do something useful here with terr.
> }
> // let unknown errors percolate up the stack.
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.
Aleksey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk