Boost logo

Boost :

From: scleary_at_[hidden]
Date: 2001-03-20 17:43:37

> 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.

Agreed; exceptions are better for unforseeable run-time errors; asserts are
more suited for double-checking invariants. I've tried several different
Win32 API return value checking methods, and the one that I settled on is
  if (!EmptyClipboard())
where Win32_error is a class I've defined whose static member function
"raise" will throw an exception of that type.

Unexpected errors are propogated up the stack, and at the topmost level (in
WinMain), I just have a catch for std::exception which prints the message as
a fatal error and (cleanly) shuts down.

My prefered style is more verbose than some, but I prefer this over the
style (or BOOST_CHECK or whatever you want) because I wanted a better error
message (like letting me know what Win32 function had the error -- also can
pass context information and the error code as optional parameters), but
without the run-time overhead if the error didn't occur.


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