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