Boost logo

Boost Users :

Subject: Re: [Boost-users] [Test] Funny Business with vector::at() out-of-range
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2016-02-10 21:23:30


On 11/02/2016 07:52, Merrill Cornish wrote:
> I posted a question a couple of days ago: "Throws 'Escaping' both
> BOOST_CHECK_THROW and try{}". I found that BOOST_CHECK_EXCEPTION which
> is working for me elsewhere fails the same way. So, an out-of-range
> std::vector::at() seems to be the common element.
>
> In the definition of at(), the out-of-range response is handled by
> __throw_out_of_range_fmt(). When I looked up that one, I found
>
> void
> __throw_out_of_range_fmt(const char*, ...) __attribute__((__noreturn__))
> __attribute__((__format__(__gnu_printf__, 1, 2)));
>
> in functexcept.h. To my admittedly less-than-expert eye, there doesn't
> seem to be an actual throw() here. On the other hand, the entire file
> are entries like this for various exceptions.

You've already found the answer to your original question in the other
thread, but just FYI:

These are just declarations, with the implementations in the library
source rather than the headers. The implementation either throws (when
exceptions are enabled) or calls abort() (when exceptions are disabled).

The "noreturn" attribute indicates that they never return normally (they
always throw or abort), which allows the compiler to make certain
assumptions when optimising.

Otherwise there's nothing special about these; they're just like any
other function that throws -- as long as you don't disable exceptions.

(And if it helps, if you did disable exceptions you would have seen a
different error message than the one in your prior thread.)


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