|
Boost Users : |
Subject: Re: [Boost-users] [exception] array tags
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2009-10-25 05:55:13
On Sun, Oct 25, 2009 at 12:46 AM, Diederick C. Niehorster
<dcnieho_at_[hidden]> wrote:
> On Sun, Oct 25, 2009 at 3:06 PM, Emil Dotchevski
> <emildotchevski_at_[hidden]> wrote:
>> Or (if you throw std::out_of_range a lot) just derive from it and
>> boost::exception, then you don't need to use enable_error_info:
>>
>> struct my_out_of_range: virtual std::out_of_range, virtual boost::exception { };
>>
>> BOOST_THROW_EXCEPTION(my_out_of_range() <<
>> std_range_which(Rows()!=M.Rows()? "row" : "col");
>
> This does not compile (on VS2008), giving me at call site:
> error C2512: 'my_out_of_range::my_out_of_range' : no appropriate
> default constructor available
> I have tried adding a default constructor,
> struct my_out_of_range: virtual std::out_of_range, virtual
> boost::exception {my_out_of_range(){};};
> but then i get the error:
> error C2512: 'std::out_of_range::out_of_range' : no appropriate
> default constructor available
Right, I forgot that std::out_of_range takes a string. You correctly
wrote a default constructor for your exception type, in that
constructor simply pass a string literal to std::out_of_range's
constructor:
my_out_of_range::my_out_of_range():
std::out_of_range("My error") { }
(That string will show up from the what() member function of std::exception.)
Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode
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