This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Throwing std::ios_base::failure on formatted input with gcc 6.2
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Edward Diener <eldlistmailingz at tropicsoft dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Thu, 27 Oct 2016 11:35:21 +0100
- Subject: Re: Throwing std::ios_base::failure on formatted input with gcc 6.2
- Authentication-results: sourceware.org; auth=none
- References: <nuq4vs$4c5$1@blaine.gmane.org> <CAH6eHdRAhZ0Vsmt1VrpUH_RTFTtgZNYmPOoAMmxA0epQZVGdPw@mail.gmail.com> <CAH6eHdQDp2-j_+HYaa+fBFCB5ZcwSGT1K1fiid6o_gb=aDF4HQ@mail.gmail.com> <nurt79$rsu$1@blaine.gmane.org>
On 27 October 2016 at 04:44, Edward Diener wrote:
> On 10/26/2016 7:51 AM, Jonathan Wakely wrote:
>> They both have a base class of std::runtime_error so you can still
>> catch it as that, or std::exception.
>>
>
> The program:
>
> #include <iostream>
> #include <sstream>
> int main()
> {
> std::stringstream ss;
> ss.exceptions(std::ios_base::failbit | std::ios_base::badbit);
> char c;
>
> try
> {
> ss >> c;
> std::cout << "Exception not thrown.";
> }
> catch (std::runtime_error &)
> {
> std::cout << "Exception std::runtime_error thrown.";
> }
> catch (...)
> {
> std::cout << "Unknown exception thrown.";
> }
> }
>
> when built with gcc-6.2 outputs:
>
> 'Unknown exception thrown.'
>
> According to what you have written above I would expect the output to be
>
> "Exception std::runtime_error thrown."
>
> What am I missing here ?
That I was wrong to say both types have a std::runtime_error base.
C++98 says std::ios_base::failure derives directly from
std::exception.