What happens if an exception occurs in a destructor in C++?
- The program will retry the destructor
- A default destructor is called
- The program terminates
- The exception is ignored
If an exception is thrown from a destructor, and it's not caught within the destructor, the C++ runtime system will terminate the program. Destructors are often invoked during stack unwinding when an exception is thrown, so allowing exceptions to propagate out can lead to unpredictable behavior.
Loading...
Related Quiz
- When a class contains a pointer to memory allocated in class, we should define a _______.
- Creating user-defined exceptions in C++ can be achieved by inheriting the _______ class.
- How does the continue statement affect the execution of a nested loop structure?
- What is the significance of the "default" case in a switch-case statement?
- What is the primary benefit of using class templates in C++?