Are destructors called after throwing exception or std::exit [duplicate]

  c++, c++11

As a follow up to this question.

I would like to ask the following:

I have a class A

class A
{
    public:
        ~A(){std::cout << "The destruction of A is called" << std::endl;}
};

and a function which is going to force the shutdown of the program

void GetUserInput()
{
    //std::exit(EXIT_FAILURE);
    throw std::runtime_error("one two three");
}

The main function is:

int main(int argCount, char *args[])
{

   A obj1;
   GetUserInput();

    return 0;

}

When the std::runtime_error or the std::exit command is executed the class destructor is not called. Is this normal behavior? When the program exits shouldnt it destroy the objects that were previously created?

Source: Windows Questions C++

LEAVE A COMMENT