Boost logo

Boost Users :

Subject: Re: [Boost-users] boost exception tutorial
From: Michael Crawford (mbcrawfo_at_[hidden])
Date: 2009-04-01 11:39:37


> Something that confuses me a little in the exception documentation is the
> struct tag used when typedef'ing error_info<>. It's unclear if these
> tags are coming
> from boost exception headers, std headers (like the in the case below) or if
> these must be explicitly defined by the user, or if the simple fact
> that of using
> them in the typedef is enough to declare them.
>
> typedef boost::error_info<struct tag_std_range_min,size_t> std_range_min;
>
> So the above is equivalent to the below?
>
> struct tag_std_range_min;
> typedef boost::error_info<tag_std_range_min,size_t> std_range_min;
>
> It may not be obvious to everyone ;-)  Wasn't to me at first.  Thanks, --DD

I'm certainly not an expert on boost::exception (just started
integrating it into my project a few days ago), but it appears to me
that the purpose is twofold:
-You can easily have multiple error_info objects which hold the same
type of data, but for different purposes. Say for example a file
loading error, where you want to report the filename and a description
of the error in two seperate error_info's; using the struct type as a
template parameter gives you a way to easily distinguish between them.
-It allows you to describe the information the error_info contains
once, when you declare the struct in the typedef. Saves you from
having to type in the info every time you use a particular error_info

Hope that helps,
MC


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