fork download
  1. #include <stdio.h>
  2.  
  3.  
  4. class Ana
  5.  
  6. {
  7. int x;
  8.  
  9. public:
  10.  
  11. Ana(int c);
  12.  
  13. Ana(const Ana & rhs) {printf("\nKONSTRUKTOR Ana copy %p %p\n",this,& rhs);}
  14.  
  15. ~Ana() {}
  16.  
  17. int ghf() const {return x;}
  18.  
  19. class A
  20.  
  21. {
  22.  
  23. public:
  24.  
  25. A() {printf("\nKONSTRUKTOR A %p\n",this);}
  26.  
  27. A(const A & rhs) {printf("\nKONSTRUKTOR A copy %p %p\n",this,& rhs);}
  28.  
  29. ~A() {printf("\nDESTRUKTOR A %p\n",this);}
  30. };
  31.  
  32. class B : public A
  33.  
  34. {
  35.  
  36. public:
  37.  
  38. B() {printf("\nKONSTRUKTOR B %p\n",this);}
  39.  
  40. B(const B & rhs) : A(rhs) {printf("\nKONSTRUKTOR B copy %p %p\n",this,& rhs);}
  41.  
  42. ~B() {printf("\nDESTRUKTOR B %p\n",this);}
  43. };
  44.  
  45. class C : public B
  46.  
  47. {
  48.  
  49. public:
  50.  
  51. C() {printf("\nKONSTRUKTOR C %p\n",this);}
  52.  
  53. C(const C & rhs) : B(rhs) {printf("\nKONSTRUKTOR C copy %p %p\n",this,& rhs);}
  54.  
  55. ~C() {printf("\nDESTRUKTOR C %p\n",this);}
  56. };
  57. };
  58.  
  59. Ana :: Ana(int c) :
  60.  
  61. x(c)
  62.  
  63. {
  64. if(c == 0) throw B();
  65.  
  66. if(c < 0) throw A();
  67.  
  68. if(c > 10) throw C();
  69. }
  70.  
  71. int main()
  72.  
  73. {
  74. try
  75.  
  76. {
  77. Ana s(11);
  78.  
  79. printf("\n-------- %d\n",s.ghf());
  80. }
  81.  
  82.  
  83. catch (Ana :: C &a)
  84.  
  85. {
  86. printf("\n****** c > 10\n");
  87. }
  88.  
  89. catch (Ana :: B & a)
  90.  
  91. {
  92. printf("\n****** c == 0\n");
  93. }
  94.  
  95.  
  96. catch (Ana :: A & a)
  97.  
  98. {
  99. printf("\n****** c < 0\n");
  100. }
  101.  
  102.  
  103.  
  104.  
  105. return 0;
  106. }
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
KONSTRUKTOR A 0x9548068

KONSTRUKTOR B 0x9548068

KONSTRUKTOR C 0x9548068

****** c > 10

DESTRUKTOR C 0x9548068

DESTRUKTOR B 0x9548068

DESTRUKTOR A 0x9548068