RE: [boost] errorcheck (was Standard C Library and C++ / BOOST)

Thorsten Ottosen wrote:
"Reece Dunn" <msclrhd@hotmail.com> wrote in message
A trick I use when handling HRESULT error codes is to have a class like this (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. e.g. try { 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; try { 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. Regards, Reece _________________________________________________________________ It's fast, it's easy and it's free. Get MSN Messenger today! http://www.msn.co.uk/messenger
participants (1)
-
Reece Dunn