fork(2) 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.  
  33. MyClass* arr = new MyClass();
  34.  
  35. std::cout<<"Did destruction happened before here?"<<std::endl;
  36.  
  37. delete arr;
  38.  
  39.  
  40. return 0;
  41.  
  42. }
Runtime error #stdin #stdout #stderr 0s 3472KB
stdin
Standard input is empty
stdout
Contructor has been called
stderr
terminate called after throwing an instance of 'Exception'