I have a try catch inside a contructor in C++ class
class jsonAdap
{
jsonAdap(const char *text)
{
try
{
parsejson(text);//this calls a libjson function that throws the expection throw std::invalid_argument("exception")
}
catch(std::invalid_argument)
{
cout<<"Exception captured:"<<endl"
}
}
}
When i'm creating an object of this class, it gives the error and stops terminate called after throwing an instance of 'std::invalid_argument'.
this is the case with cross compiled on ARM (with -O0 -g3 -Wall -c -fmessage-length=0 -pthread -Wno-reorder -std=gnu++0x -fstack-protector-all -Wno-format-contains-nul -Wno-format-extra-args -Wno-format-zero-length) ,
but on windows it catches the error properly.
When i try a sample application with the same options from cross compiling, on the board it works perfectly.
Is there any compiler setting that could be contributing to this behaviour, that i may not have noticed?
Any suggestions?
below is the sample application
class ctest
{
public:
ctest()
{
int x = -1;
try {
cout << "Inside try \n";
if (x < 0)
{
throw std::invalid_argument("test");
cout << "After throw (Never executed) \n";
}
}
catch (std::invalid_argument &e) {
cout << "Exception Caught \n";
}
}
void test(){};
};
int main( int argc, char* argv[] )
{
cout << "Before try \n";
ctest c;
cout << "cdone "<<endl;
return 0;
}