I\'ve written the below code which overloads the new
and delete
operators and throws an exception in the destructor.
When the exception is
The destructor is called before calling to the delete operator. See cppreference - delete expression
If expression is not a null pointer, the delete expression invokes the destructor (if any) for the object that's being destroyed, or for every element of the array being destroyed (proceeding from the last element to the first element of the array). After that, unless the matching new-expression was combined with another new-expression (since C++14) the delete expression invokes the deallocation function, either operator delete (for the first version of the expression) or operator delete[] (for the second version of the expression).
Due to this order of operations, the destructor is called and throws an exception before your overloaded version of the delete operator is called.