The exceptions are not being caught.

Hello,

Looks like that none of exceptions are being caught. e.g. if I run a code below it will not fall into any of catch.

I use gcc 4.6.3 on Ubuntu 12.04. CDFLAGS = -g -std=c++0x

Thank you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream>
#include<stdexcept>
using namespace std;

int main()
{
    try
    {
        throw out_of_range("hello kitty");
    }
    catch(const out_of_range& le)
    {
        cout << le.what() << endl;
    }
    catch(...)
    {
        cout << "error" << endl;
    }

    int stop = 0;
}
closed account (S6k9GNh0)
Problem with your toolchain, not C++:

http://codepad.org/Tatd1iHD
http://liveworkspace.org/code/26fJ4j$0
Last edited on
I also get the output "hello kitty" but when I debug the code it does not step into catch block.
It works as expected for me on:
CentOS 5.2/gcc 4.1.2
ArchLinux/gcc 4.7.2
ArchLinux/icc 13.0.1

Code, x.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <stdexcept>

int main()
{
	std::string str = "hello";

    try
    {
        throw std::out_of_range(str);
    }
    catch (const std::out_of_range& e)
    {
        std::cout << "std::out_of_range: " << e.what() << std::endl;
    }
    catch (const std::exception& e)
    {
        std::cout << "std::exception: " << e.what() << std::endl;
    }
    catch (...)
    {
       std:: cout << "error" << std::endl;
    }

	return 0;
}


Built with make x for gcc, and make CXX=icc x for Intel. (GNUMake doesn't need a make file for this.)
Last edited on
Thanks guys, I got it now.
Topic archived. No new replies allowed.