I have following code,
my_class.cpp
#include "my_class.h"
my_class::my_class(int m)
{
try
{
my_method();
throw My_Exception();
}
catch(exception &e)
{
delete this;
throw;
}
}
my_class::~my_class()
{
for(auto &el : my_member)
if(el!=NULL)
delete el;
}
void my_class::my_method()
{
for(int i ; i<5 ; i++)
my_member.push_back(new dfa(i)); //dfa is another class
}
my_class.h
#include "dfa.h"
#include "exception.h"
using namespace std;
class my_class
{
public :
my_class();
~my_class();
void my_method();
private :
vector<dfa *> my_member;
};
exception.h
#include <exception>
class My_Exception : public exception
{
public:
const char * what () const throw ()
{
return "Generic Exception";
}
};
main.cpp
#include <iostream>
#include "my_class.h"
int main()
{
try
{
my_class *ptr = new my_class(3);
}
catch(exception &e)
{
cout<<e.what()<<endl;
}
}
the class dfa is missing, but is a normal class. The problem is in the catch, when i do delete this the denstructor is invoked and dynamics objects of class dfa deallocated but the exception isn't relaunched. The execution flow doesn't return to main (in the catch block of the main) because there is a segmentation fault. What could be the problem?
(I can't use shared or auto ptr to handle memory because I'm using a big library) (I'm using C++11)