This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C++ throw is crashing

Hi, 

C++ programs crash on throw statement execution. 

Ex. Consider the following c++ program,

 

 

#include <iostream>

using namespace std;

class DivideByZero {

    public:

        double divisor;

        DivideByZero(double x);

};

DivideByZero::DivideByZero(double x) : divisor(x)

{}

int divide(int x, int y) {

    if(y==0)     {

        throw DivideByZero(x);

    }

int main () {

try {

   divide(12, 0);

}

catch (DivideByZero divZero)  {

   cerr<<"Attempted to divide "<<divZero.divisor<<" by zero";

}      

return 0;

}

 

compile the programs

#arm_v5t_le-g++  -o test.out test.cpp

The program aborts with the following print. 

terminate called after throwing an instance of 'DivideByZero'

terminate called recursively

Aborted

 

 LDD output on the executable

#arm_v5t_le-ldd test.out

libstdc++.so.6 => /opt/montavista/pro/devkit/arm/v5t_le/target/usr/lib/libstdc++.so.6 (0xdead1000)

libm.so.6 => /opt/montavista/pro/devkit/arm/v5t_le/target/lib/libm.so.6 (0xdead2000)

libgcc_s.so.1 => /opt/montavista/pro/devkit/arm/v5t_le/target/lib/libgcc_s.so.1 (0xdead3000)

libc.so.6 => /opt/montavista/pro/devkit/arm/v5t_le/target/lib/libc.so.6 (0xdead4000)

/lib/ld-linux.so.3 => /opt/montavista/pro/devkit/arm/v5t_le/target/lib/ld-linux.so.3 (0xdead5000)

 

Platform : DM365, IPNC2.6 

Compiler Version : arm_v5t_le-g++ (GCC) 4.2.0 (MontaVista 4.2.0-16.0.32.0801914 2008-08-30)

lib c++  version : libstdc++.so.6.0.9

lib c version : libc.so.6

Is there anything wrong done here. Any build options  to get rid of the error ?

Thanks &  Regards,

Sambhav