Advertisement
vvccs

exceptional handling

Jun 6th, 2023
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Arr_ope
  5. {
  6. public:
  7.     int arr[5] = {1, 3, 5, 5, 6};
  8.     void arrOperation(int value, int pos)
  9.     {
  10.         arr[pos] = value;
  11.     }
  12. };
  13. class my_exception
  14. {
  15. };
  16. int main()
  17. {
  18.     Arr_ope ar;
  19.     int pos;
  20.     int value;
  21.     cout << "\n Enter value to be added in array: ";
  22.     cin >> value;
  23.     cout << "\n Enter position where value is to added: ";
  24.     cin >> pos;
  25.  
  26.     if (pos > 5)
  27.     {
  28.         try
  29.         {
  30.             throw my_exception();
  31.         }
  32.         catch (my_exception t)
  33.         {
  34.             cout << "\n\n Caught Exception of my_exception class" << endl;
  35.             cout << "\n Trying to access out of range position of Array";
  36.         }
  37.     }
  38.     ar.arrOperation(value, pos);
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement