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.

Throwing terminates application

Expert 1635 points


Hi,

I am developing a C++ application based on the MSP430.  I have found a problem with exceptions handling that I can reproduce using the following code snippet:

#include <msp430.h>
#include <memory>


//#define STATIC
//#define RAWPTR
#define SMARTP

class A
{
    A(const A&);
    A& operator=(const A&);

    int var;

public:
    A(int num) : var(num){};
    ~A() {};

    void check(int numero);
};


void A::check(int numero)
{
    if ( var == numero )
        return;

    throw (int)578;
}

int main(void)
{
#ifdef STATIC
    A my_a(4);
#elif defined(RAWPTR)
    A* ptA = new A(9);
#elif defined(SMARTP)
    std::auto_ptr<A> ptA(new A(9));
#else
#error "One option must be chosen!"
#endif

    try
    {
#ifdef STATIC
        my_a.check(4);
        my_a.check(7);
#endif

#if defined(RAWPTR) or defined(SMARTP)
        ptA->check(9);
        ptA->check(7);
#endif
    }
    catch(...)
    {
#ifdef RAWPTR
        delete ptA;
#endif
        return -1;
    }
}

When the object is instantiated statically the catch works fine (I tried also with mere functions and it works fine too).  The problem is when I do dynamic instantiation, either with a raw pointer or a smart one: the program will re-start.  I have also tried making the class copyable.  The --exceptions option is enabled.

What am I missing?

Many thanks,

Pibe

  • Another piece of information: if I try compiling with --lc (large code model) option the results are the same.  If I add --ld (large data model) all three cases fail.

    I have tried re-installing CCS and obtained the same results.

    Not related to the main topic and yet interesting is the fact that if I try enabling throwing on extern C functions I got the following message when compiling:

    #24017-D Option --extern_c_can_throw is not valid without --exceptions (ignored)

    Which is weird because --exceptions is enabled (as shown in the configuration form and confirmed by the fact the code is compiled).

    I am using CCS 5.5 with compiler 4.2.3

    Please somebody from TI can look into this?

    Thanks,

    Pibe

  • Here it is a screen capture for the raw pointer throw fail:

  • Found it: it was the heap size.  It comes with a minute 160 bytes, I increased it to 400 and voila'!

    Could it be possible for CCS to either warn or automatically increase the heap size when exceptions handling is selected?

    Pibe

  • Pibe said:
    Could it be possible for CCS to either warn or automatically increase the heap size when exceptions handling is selected?

    I filed SDSCM00049771 in the SDOWP system to request this enhancement to the linker.  Feel free to follow it with the SDOWP link below in my signature.

    Thanks and regards,

    -George

  • Cool.  Thank you, George.