My dev env is: Ubuntu 16.04 64bit. g++ 5.4.0 64bit toolchain. I am porting some code from Windows to Linux that invloves ASIO lib.In some places I have to a logic to catch exceptions from asio::read()
and asio::write()
. And those are not being caught by try...catch() neither in release nor in debug modes. So to understand if the problem with ASIO or my usage of it I just put this code in my main.cpp:
class Foo
{
public:
Foo(){}
void ThrowExc()
{
throw std::runtime_error("I am exception!");
}
};
int main(int argc, char *argv[])
{
Foo f;
try
{
f.ThrowExc();
}
catch(std::exception &e)
{
std::cout<<"Exception caught" << std::endl;
}
It doesn't work.The program crashes with the call stack looking like this:
0 0x00007ffff57188bd __cxa_throw
1 0x000000000040e5ab Foo::ThrowExc /main.cpp 32
2 0x000000000040d16c main main.cpp 45
My C++ compiler flags are: -g;-std=c++14;-Wall;-fexceptions;-fPIC
UPDATE:
Some commenters pointed out that the issue can be with my project's code somewhere else. So I created a new empty project from scratch, main.cpp
only. With the code shown above. Still the same problem.
UPDATE 1:
I am still not sure what was the exact issue.But It looks like my GNU version tool-chains were not set correctly. I had gcc from version x and g++ from version Y. So I reinstalled the compilers and reset their symlinks. Used this page for manual.