Throwing std::ios_base::failure on formatted input with gcc 6.2
Jonathan Wakely
jwakely.gcc@gmail.com
Thu Oct 27 10:35:00 GMT 2016
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.
More information about the Gcc-help
mailing list