Boost logo

Boost :

Subject: [boost] [boost::exception] operator >>
From: Gaydov Victor (victor.gaydov_at_[hidden])
Date: 2009-04-17 10:55:56


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.





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