samedi 25 septembre 2021

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

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?

Aucun commentaire:

Enregistrer un commentaire