|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2003-03-22 12:13:52
Terje Slettebø <tslettebo_at_[hidden]> writes:
>>From: "Gennaro Prota" <gennaro_prota_at_[hidden]>
>
>> On Sat, 22 Mar 2003 09:52:07 -0500, David Abrahams
>> <dave_at_[hidden]> wrote:
>>
>> >Kevlin Henney <kevlin_at_[hidden]> writes:
>>
>> >> However, the decision as to whether this should be in the 'what' string
>> >> is perhaps one that can be revisited. It would be feasible to avoid any
>> >> allocation issues at all by leaving the human readable string as
> general
>> >> as it was before and adding type_info members that described the source
>> >> and target types.
>> >
>> >Yes, that was my suggestion.
>>
>> I'm happy that std::type_info has a private copy constructor. Hadn't
>> it been for that, my suggestion to use just a couple of typedefs would
>> have been routinely rejected :-)
>
> Storing a couple of type members is not enough, by itself. How would a
> catch-clause taking e.g. a reference to bad_lexical_cast access them? To
> access the typedefs, you need to know the exact type thrown, which means you
> need to know the types to begin with...
There's absolutely no reason I can see to make the exact exception
type depend on the types concerned. Just use a straightforward
class, something along the lines of:
struct bad_lexical_cast : std::exception
{
bad_lexical_cast(
std::type_info const& src, std::type_info const& dst)
: m_src(src), m_dst(dst) {}
char const* what() throw() { return "bad_lexical_cast"; }
std::type_info const& src() const { return m_src; }
std::type_info const& dst() const { return m_dst; }
private:
std::type_info const& src;
std::type_info const& dst;
};
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk