[boost::exception] operator >>

hello! i'm using boost::exception in one project and did small modification for myself, what do you think about it ? i don't want to create a lot of exception classes, because my 'catches' will use only a few of them anyway. but while exception is throwing, some functions add different information to it (with operator <<) that is useful in diagnostic messages. so when we decide to extract that information from exception, we need to study what useful information it has. instead of using if-else it'll be nice to use inheritance of _errors_ (not exceptions), for example: throw our_exception () << error_1 (); ... catch (our_exception & e) { re-throw e << error_2 (); } ... catch (our_exception & e) { shared_ptr <base_of_error_1_and_2> ptr; while (e >> ptr) cout << ptr->format_error_message(); } i attached 'test.cpp' and 'operator.cpp' with stupid realization and example. if somebody thinks it can be useful of cause i can rewrite it to make it more practical.

i'm sorry, i forgot to add most important thing: it is working since error_info should inherit both of error_info_base and its 'Tag' parameter, so dynamic_cast will work properly.

On Fri, Apr 17, 2009 at 7:55 AM, Gaydov Victor <victor.gaydov@gmail.com> wrote:
hello! i'm using boost::exception in one project and did small modification for myself, what do you think about it ?
i don't want to create a lot of exception classes, because my 'catches' will use only a few of them anyway. but while exception is throwing, some functions add different information to it (with operator <<) that is useful in diagnostic messages.
so when we decide to extract that information from exception, we need to study what useful information it has. instead of using if-else it'll be nice to use inheritance of _errors_ (not exceptions), for example:
throw our_exception () << error_1 (); ... catch (our_exception & e) { re-throw e << error_2 (); } ... catch (our_exception & e) { shared_ptr <base_of_error_1_and_2> ptr; while (e >> ptr) cout << ptr->format_error_message(); }
I understand what you are doing but I don't understand why. Could you provide a non-abstract example of a use case that benefits from this addition? Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode
participants (2)
-
Emil Dotchevski
-
Gaydov Victor