Advertisement
avr39ripe

Pv913ExceptionBasics

Jul 28th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <chrono>
  3.  
  4. int linearSearch(int* arr, int size)
  5. {
  6.     int idx{ -1 };
  7.  
  8.     //.....
  9.  
  10.     return idx;
  11. }
  12.  
  13. //float divide(float a, float b)
  14. //{
  15. //  if (b == 0)
  16. //  {
  17. //      //std::cout << "ERROR Division by zero!!!\n";
  18. //      return false;
  19. //  }
  20. //
  21. //  res = a / b;
  22. //  return true;
  23. //}
  24. int enterVal()
  25. {
  26.     int val{ 0 };
  27.  
  28.     std::cout << "Enter val [1..5]\n";
  29.     std::cin >> val;
  30.  
  31.     if (val < 1) { throw - 1; };
  32.     if (val > 5) { throw 1; };
  33.  
  34.     return val;
  35. }
  36.  
  37. int main()
  38. {
  39.     //try
  40.     //{
  41.     //  std::cout << "Oh, good val = " << enterVal() << '\n';
  42.     //}
  43.    
  44.     catch (int x)
  45.     {
  46.         if (x == -1)
  47.         {
  48.             std::cout << "Too small value!\n";
  49.         }
  50.         if (x == 1)
  51.         {
  52.             std::cout << "Too big value!\n";
  53.         }
  54.     }
  55.  
  56.     catch (double x)
  57.     {
  58.         std::cout << "Double exception " << x << '\n';
  59.     }
  60.  
  61.     catch (const char* str)
  62.     {
  63.         std::cout << "const char* exception " << str << '\n';
  64.     }
  65.  
  66.     std::cout << "Main NORMALLY works again!\n";
  67.     /*float result{ 345 };
  68.     if (divide(-2, 2, result))
  69.     {
  70.         std::cout << "Good result " << result << '\n';
  71.     }
  72.     else
  73.     {
  74.         std::cout << "NO result!\n";
  75.     }*/
  76.  
  77.     //if (linearSearch < 0)
  78.     //{
  79.     //  std::cout << "Not found1 :(\n";
  80.     //}
  81.  
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement