Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2004-03-27 11:39:15

Thorsten Ottosen wrote:
>"Reece Dunn" <msclrhd_at_[hidden]> wrote in message
> > A trick I use when handling HRESULT error codes is to have a class like
> > (adapted for int error type):
>Maybe you should start on such a small helper library and submit it?

I have attached what I have so far. It is a policy-based approach that
allows you to specify the error type/check mechanism and a message holder.
It also fixes the throw on constructor problem mentioned by others.


   boost::errorcheck<> ec = 7;

   ec = -1;
   std::cout << "Hello\n";
catch( boost::errorcheck<> ec )
   std::cout << "error: check failed" << '\n';

output ==>
   error: check failed

If you want to note the function called from, like in Volodya's examples,
you can use:

typedef boost::errorcheck< boost::policy::error_storage<>,
boost::policy::errormsg_storage >

   msgerrorcheck em;
   em( "open" ) = -1;
   em( "write" ) = 3;
catch( msgerrorcheck em )
   std::cout << "error: " << em.get_msg() << '\n';

output ==>
   error: open

This is a slightly different syntax, but gives what is intended.

NOTE: I have not yet provided an errno class, but it should not be difficult
to do.


It's fast, it's easy and it's free. Get MSN Messenger today!

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