Guest User

Untitled

a guest
Mar 2nd, 2021
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdexcept>
  3. #include <string>
  4. #include <cmath>
  5. #include <limits>
  6.  
  7. using namespace std;
  8.  
  9. void my_unexpected()
  10. {
  11.     cout<<"был вызван unexpected"<<endl;
  12.     exit(0);
  13. }
  14.  
  15. void my_terminate()
  16. {
  17.     cout<<"был вызван terminate"<<endl;
  18.     exit(0);
  19. }
  20.  
  21. class MyException0 : public exception
  22. {
  23.     public:
  24.  
  25.         MyException0():exception(){}
  26. };
  27.  
  28. class MyException1 : public invalid_argument
  29. {
  30.     public:
  31.  
  32.         MyException1(const string& error_msg):invalid_argument(error_msg){}
  33. };
  34.  
  35. class MyException2 : public runtime_error
  36. {
  37.     public:
  38.  
  39.         MyException2(const string& error_msg):runtime_error(error_msg){}
  40. };
  41.  
  42. class Vector0
  43. {
  44.     private:
  45.  
  46.         int x;
  47.         int y;
  48.         int z;
  49.  
  50.         void Init(int x, int y, int z)
  51.         {
  52.             this->x = x;
  53.             this->y = y;
  54.             this->z = z;
  55.         }
  56.  
  57.     public:
  58.  
  59.     Vector0(int x=0, int y=0, int z=0) throw(invalid_argument, bad_exception)
  60.     try
  61.     {
  62.         cout<<x<<endl;
  63.         if(abs(x)>numeric_limits<int>::max() || abs(y)>numeric_limits<int>::max() || abs(z)>numeric_limits<int>::max())
  64.             throw invalid_argument("слишком большое или маленькое значение координат");
  65.  
  66.         this->x = x;
  67.         this->y = y;
  68.         this->z = z;
  69.     }
  70.     catch(const invalid_argument& error)
  71.     {
  72.         cout<<error.what()<<endl;
  73.     }
  74.  
  75.  
  76. };
  77.  
  78. int main()
  79. {
  80.     setlocale(LC_ALL, "Russian");
  81.     set_terminate(my_terminate);
  82.     set_unexpected(my_unexpected);
  83.  
  84.     try
  85.     {
  86.         Vector0 a(31231231233131231,12,23);
  87.         cout<<numeric_limits<int>::min()<<endl;
  88.     }
  89.     catch(const exception& error)
  90.     {
  91.         cout<<error.what()<<endl;
  92.     }
  93.  
  94. }
  95.  
Advertisement
Add Comment
Please, Sign In to add comment