Boost logo

Boost Users :

Subject: Re: [Boost-users] [Exception] How do I inherit custom exception hierarchy from std::runtime_error rather than from std::exception?
From: Eric Prud'hommeaux (eric_at_[hidden])
Date: 2013-11-28 01:39:55


On Nov 27, 2013 9:52 PM, "Emil Dotchevski" <emildotchevski_at_[hidden]> wrote:
>
> On Wed, Nov 27, 2013 at 8:19 AM, Egor Tensin <egor.tensin_at_[hidden]>
wrote:
> > The issue that's confusing me arose from my intention of inheriting my
> > exception classes from std::runtime_error rather than from
> > std::exception. It seemed logical to me, as my exceptions are really
> > runtime errors; getting something meaningful via what() also seemed
> > like a good idea. However, this doesn't compile:
>
> <cut>
>
> > struct foo_error : virtual boost::exception, virtual std::runtime_error
> > {
> > explicit foo_error(const char *const what)
> > : std::runtime_error(what)
> > { }
>
> Yes, you'd have to use non-virtual inheritance if you want to be able
> to pass the what parameter like this. However, I would recommend
> deriving virtually from std::exception and using different exception
> types rather than different what strings for different failures. It is
> usually appropriate to override what() and implement it in terms of
> diagnostic_information_what (see
>
www.boost.org/doc/libs/release/libs/exception/doc/diagnostic_information_what.html
.)

Your advice makes sense to me but I'm curious what semantics you write off,
either explicit in the runtime_error definition or implied by library or
development tool interpretation of runtime_error.

> --
> Emil Dotchevski
> Reverge Studios, Inc.
> http://www.revergestudios.com/reblog/index.php?n=ReCode
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users



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