Program 9: Division By Zero Error
#include <iostream>
using namespace std;
int main() {
int a, b;
float c;
cout << "Enter the value of a: ";
cin >> a;
cout << "Enter the value of b: ";
cin >> b;
try {
if (b != 0)
{
c=a / b;
cout << "Result is: " << c << endl;
}else{
throw "Division by zero error!";
}
}
catch (const char* msg) {
cout << "Error: " << msg << endl;
}
return 0;
}
Program 10: Array out of bound Error
#include <iostream>
#include <stdexcept>
using namespace std;
int main()
int arr[] = {1, 2, 3, 4, 5};
int size = 5;
int index;
cout << "Enter an index to access the array: ";
cin >> index;
try
if (index < 0 || index >= size)
throw out_of_range("Index out of bounds");
else
cout << "Value at index " << index << " is: " << arr[index] << endl;
catch (const out_of_range& e)
cout << "Exception caught: " << e.what() << endl;
return 0;