
On Sun, Oct 25, 2009 at 12:46 AM, Diederick C. Niehorster
On Sun, Oct 25, 2009 at 3:06 PM, Emil Dotchevski
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