Boost.Exception - my 2 euro cents

Hi Emil, 1. First, the idea totally rocks! 2. From the docs: struct tag_errno: boost::error_info_value<int> { }; //(1) class my_error: public boost::exception, public std::exception { }; //(2) void f() { .... throw my_error() << boost::error_info<tag_errno>(errno); //(3) } Not sure why this extra complication: Why not have this: throw my_error() << tag_errno(errno); boost::exception should know it's a tag (it derives from error_info_value) - it's just syntactic sugar. 3. I've looked at the code, and in what() function, you actually write the typeinfo's name. Well, this is fine for VC8 - lets say, but some compilers will give you some really crazy string - which, when logging will mean exactly nothing. You could provide some helper macros to actually enforce compiler to give a user-friendly name, like: #define BOOST_EXCEPTION_TAG(name,type) struct name : boost::error_info_value<type> \ { name() : boost::error_info_value<type>(#name) {} }; I believe this would help a lot debugging/logging 4. Debugging. When debugging, and you catch an exception, unless you wait for .what() to be logged somewhere, and look at that log - or something, when you "watch" that exception, you won't find anything useful. I recommend you have a directive, which if turned on, will contain .what() as string - only for debugging purposes. Thus, by watching a pointer to boost::exception, you can find out what tags it contains. Well, that's it from me! Best, John -- http://John.Torjo.com -- C++ expert ... call me only if you want things done right

Hi John,
2. From the docs:
struct tag_errno: boost::error_info_value<int> { }; //(1)
class my_error: public boost::exception, public std::exception { }; //(2)
void f() { .... throw my_error() << boost::error_info<tag_errno>(errno); //(3) }
Not sure why this extra complication:
Why not have this:
throw my_error() << tag_errno(errno);
Oh... Yes. I like this a lot, I'll look at the code tomorrow to see if there are any obstacles. I can't think of any, but it's 3AM here, who knows. :)
3. I've looked at the code, and in what() function, you actually write the typeinfo's name. Well, this is fine for VC8 - lets say, but some compilers will give you some really crazy string - which, when logging will mean exactly nothing.
Well, the type name might be mangled but it is quite readable with the compilers I've tried. Note, what() is not meant to provide a user-friendly message anyway.
You could provide some helper macros to actually enforce compiler
to give a user-friendly name, like:
#define BOOST_EXCEPTION_TAG(name,type) struct name : boost::error_info_value<type> \ { name() : boost::error_info_value<type>(#name) {} };
I believe this would help a lot debugging/logging
To be honest, I'd rather have the automatically generated type name from the compiler. It's even possible to unscramble the name if it's such an issue (compiler-specific, of course.)
4. Debugging. When debugging, and you catch an exception, unless you wait for .what() to be logged somewhere, and look at that log - or something, when you "watch" that exception, you won't find anything useful. I recommend you have a directive, which if turned on, will contain .what() as string - only for debugging purposes.
Good idea. Thanks, Emil Dotchevski
participants (2)
-
Emil Dotchevski
-
John Torjo