Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2004-03-29 12:57:55

Vladimir Prus wrote:
>John Torjo wrote:

> >>> I really wish there were exception-throwing versions -- since that
> >>> code is
> >>> boring and still contains a couple of error-handling problems.
> >>> However, most
> >>> of the functions above are acutally from POSIX, not from standard C,
> >>> so I'm
> >>> not sure how much wrapped C functions would help me.

> > Unless I'm mistaken, you're talking something similar to Andrei
> > Alexandrescu's ENFORCE:
> >

>Yes, you're right. However, there's one additional wish -- I'd like an
>appraoch different macroses for different functions. E.g. for POSIX calls I
>only encounter -1 returns and NULL returns for error reporting. So I'd like

> int tty = check(open(check(ctermid(0)), O_RDRW);

>to work. I guess this could be done by providing two overloads for the
>'Wrong' function...., but not, the 'Enforcer' template only works for
>specific type of return value :-(

My errorcheck class (see other posts) has an error policy where you can
change the fail test. The default is to test errorcode < 0.

A current weakness is that it does not return the value passed to it on
assignment, so you cannot use exactly like the above example. I have been
updating it to support errno handling, but this (at present) requires
something like:

   boost::errorcheck< ... > check;

   FILE * fp = ::fopen( 0, "r" );
   check( fp != 0 ); // assert-like syntax
   ::fclose( fp );

If you are interested, I'll work on supporting constructs like your example


Express yourself with cool new emoticons

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