Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include "iostream"
  2. #include "exception"
  3. using namespace std;
  4.  
  5. class Except:public exception
  6. {
  7. public:
  8.     const char* what() const noexcept
  9.     {
  10.         return "Error!";
  11.     }
  12. };
  13.  
  14. class Time
  15. {
  16.     int hour;
  17.     int minute;
  18.     int second;
  19. public:
  20.     Time(int hour,int minute,int second)
  21.     {
  22.         if (hour >= 24)
  23.             throw Except();
  24.         else if (minute >= 60)
  25.             throw Except();
  26.         else if (second >= 60)
  27.             throw Except();
  28.  
  29.         this->hour = hour;
  30.         this->minute = minute;
  31.         this->second = second;
  32.         cout << "correct" << endl;
  33.     }
  34. };
  35.  
  36. int main()
  37. {
  38.     try
  39.     {
  40.         Time A(23, 60, 50);
  41.     }
  42.     catch (exception& e)
  43.     {
  44.         cout << e.what() << endl;
  45.     }
  46.  
  47.     try
  48.     {
  49.         Time B(20, 50, 50);
  50.     }
  51.     catch (exception& e)
  52.     {
  53.         cout << e.what() << endl;
  54.     }
  55.  
  56.     system("pause");
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement