Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "iostream"
- #include "exception"
- using namespace std;
- class Except:public exception
- {
- public:
- const char* what() const noexcept
- {
- return "Error!";
- }
- };
- class Time
- {
- int hour;
- int minute;
- int second;
- public:
- Time(int hour,int minute,int second)
- {
- if (hour >= 24)
- throw Except();
- else if (minute >= 60)
- throw Except();
- else if (second >= 60)
- throw Except();
- this->hour = hour;
- this->minute = minute;
- this->second = second;
- cout << "correct" << endl;
- }
- };
- int main()
- {
- try
- {
- Time A(23, 60, 50);
- }
- catch (exception& e)
- {
- cout << e.what() << endl;
- }
- try
- {
- Time B(20, 50, 50);
- }
- catch (exception& e)
- {
- cout << e.what() << endl;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement