Boost logo

Boost Users :

Subject: Re: [Boost-users] exception error_info list?
From: denis (mu_kuh_at_[hidden])
Date: 2009-10-10 09:06:10


Emil Dotchevski wrote:
> On Fri, Oct 9, 2009 at 5:48 PM, denis <mu_kuh_at_[hidden]> wrote:
> > what do you think about exposing the error_info-map of
> > boost::exception?
> >
> > I would like to get all attached error infos from one exception.
>
> I've never been able to do anything generic with the error_infos,
> other than dumping (user-unfriendly) diagnostic information, which is
> what boost::diagnostic_information is for.

I have an exception base-class which provides a virtual function
user_message() where derived classes can generate a user-friendly
message from their error_infos. See the example at the end.

> > Then, everyone could implement his own version of
> > diagnostic_information() without relying on boost internals.
>
> You do have some control over the output of diagnostic_information:
> [...]

Yes, but even if the output is not for end-users, I would like to
keep the log-file as readable as possible for the support
team. And not at least for me.

For example I don't need the line "Throw in function (unknown)"
(I rarely use BOOST_THROW_EXCEPTION) And I could use
abi::__cxa_demangle to print a more readable name of an exception
or error_info.

> > Beside that, I had another idea: When translating an exception it
> > would be possible to copy all error_infos from the originating
> > exception to the new one.  How do you handle this loss of
> > information at the time?
>
> A copy of a boost::exception shares error_info ownership with the
> original. Does this work for your use case?

I don't think so. Where could I copy the exception in the
following example, so that my_error() would have the error_infos
from e?

    struct my_error : public ex::exception {
        virtual std::string
        user_message () const {
            // format() is just a little helper function in the base
            // class using boost::get_error_info and boost::format
            return format<boost::errinfo_file_name,
                          boost::errinfo_errno>
                ("The file %1% could not be read because %2%");
        }
    };

    // -- snip --

    try {
        mylib::func(); // func throws with attached boost::errinfo_errno
    } catch (mylib::system_error& e) {
        throw my_error()
            << e??
            << boost::errinfo_file_name ("foo");
    }

regards,
Denis


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net