mrDIMAS

test 2

Dec 19th, 2015
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <memory>
  4.  
  5. using namespace std;
  6.  
  7. class Moo {
  8. private:
  9.     int mNumber;
  10. public:
  11.     Moo() : mNumber( 123 ) {
  12.         throw std::runtime_error( "Epic fail exception" );
  13.         cout << mNumber << endl;
  14.     };
  15.  
  16.     ~Moo() {
  17.         cout << "~Moo" << endl;
  18.     }
  19. };
  20.  
  21. class Foo {
  22. private:
  23.     Moo * mMoo;
  24. public:
  25.     Foo() {
  26.         mMoo = new Moo ;
  27.         cout << "Foo()" << endl;
  28.     }
  29.     ~Foo() {
  30.         cout << "~Foo()" << endl;
  31.     }
  32. };
  33.  
  34. class Bar {
  35. private:
  36.     Foo foo;
  37. public:
  38.     Bar(){
  39.         throw std::runtime_error( "Bar exception" );
  40.         cout << "Bar()" << endl;
  41.     }
  42.  
  43.     ~Bar() {
  44.         cout << "~Bar()" << endl;
  45.     }
  46. };
  47.  
  48.  
  49. void main() {
  50.     try {
  51.         Bar bar;
  52.     } catch( std::runtime_error err ) {
  53.         cout << err.what() << endl;
  54.     }
  55.     _getch();
  56. }
Advertisement
Add Comment
Please, Sign In to add comment