Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2004-03-30 18:12:05


Rob Stewart wrote:
>From: "Reece Dunn" <msclrhd_at_[hidden]>
> > What about when you use boost::policy::errormsg_storage instead of
> > boost::policy::no_errormsg_storage? Doing this allows the following:
> >
> > typedef boost::errorcheck< boost::policy::error_storage<>,
> > boost::policy::errormsg_storage >
> > errorcheckmsg;
> >
> > try
> > {
> > errorcheckmsg em;
> > em( "oops!" ) = -3; // note the special syntax
> > }
> > catch( errorcheckmsg em )
> > {
> > std::cout << "error: " << em.get_msg() << '\n';
> > }
> >
> > resulting in "error: oops!" being outputted. Using your method, the
>message
> > string will ont be passed and thus you would get "error: unspecified
>error"!
> > That is why I implemented it as above.
>
>I didn't see anything like that in the code you showed. It was
>probably in the full implementation, but I was only looking at
>what's quoted above.

I posted it as a different message (errorcheck) and have been revising it
based on comments and suggestions. The full code is attached here.

>Anyway, why must either constructor manage the string at this
>point? Why wouldn't the generation of the string occur at the
>time it is requested? That is, there is no string to copy if
>there is no string generated until the get_msg() mf is called.
>That mf can create the string (reusing it if already computed, of
>course).

It depends on what you are using it for. The string for the errno handler
*is* generated at get_msg() call-time. The above is based on an example
Volodya posted where he put the name of the function he was calling into the
code.

E.g.
   // [paraphrased]:
   if( ::read( fn, ... ) < 0 ) report_error( "read", errno );
becomes
   ec( "read" ) = ::read( fn, ... );

As another example, you could have a handler that supports windows
GetLastError and do something like:

   try
   {
      winerr( "Rectangle" ) = ::Rectangle( hDC, 10, 10, 110, 110 );
      winerr( "Ellipse" ) = ::Ellipse( hDC, 10, 10, 110, 110 );
   }
   catch( winapi_errorcheck e )
   {
      std::cout << "error: " << e.get_msg() << " - " << e.error_string() <<
'\n';
   }

NOTE: I know that mixing GUI/console does not work -- this is just a usage
demonstration.

>If you find your approach is still needed, no problem. I just
>wanted to be sure you understood what I had implied.

No worries. I understood your approach, but I was designing it to be as
flexible as possible.

Regards,
Reece

_________________________________________________________________
It's fast, it's easy and it's free. Get MSN Messenger today!
http://www.msn.co.uk/messenger




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