fork download
  1. #include <iostream>
  2.  
  3. struct Exception{
  4.  
  5. };
  6.  
  7. class MyClass{
  8.  
  9. private:
  10.  
  11. int variable;
  12.  
  13. public:
  14.  
  15. MyClass(){
  16. std::cout<<"Contructor has been called"<<std::endl;
  17. throw Exception();
  18. }
  19.  
  20. ~MyClass(){
  21. std::cout<<"Destructor has been called"<<std::endl;
  22. }
  23.  
  24. void operator delete(void* object){
  25. std::cout<<"My delete was called"<<std::endl;
  26. }
  27.  
  28.  
  29. };
  30.  
  31. int main(void)
  32. try
  33. {
  34.  
  35. MyClass* arr = new MyClass();
  36.  
  37. std::cout<<"Did destruction happened before here?"<<std::endl;
  38.  
  39. delete arr;
  40.  
  41.  
  42. return 0;
  43.  
  44. }
  45. catch(...) {
  46. throw;
  47. }
Runtime error #stdin #stdout #stderr 0s 3428KB
stdin
Standard input is empty
stdout
Contructor has been called
My delete was called
stderr
terminate called after throwing an instance of 'Exception'