#include <iostream> using namespace std; void func(int x) { try { if(x==1) throw x; else if(x==0) throw 'p'; else if(x==-1) throw 1.0; cout<<" NO Exception " << "X value " << x; cout<<"\n…
Read more3. Write a C++ program that throws Division by zero exception using try block invokes function.
#include <iostream> using namespace std; int division(int x, int y) { if( y == 0 ) { throw (0); } return (x/y); } int main () { int a,b,c; cout<<" enter 2 values"; cin>>a>>b; try { c = division(a,b); cout << "Answer is: " <&l…
Read more2. Write a C++ program that finds Voter eligibility age in India using try-catch block.
#include <iostream> using namespace std; int main() { int age; cout << "enter age of citizen\n "; cin>> age; try { if (age >= 18) { cout << "voter enroll granted - you are old enough."; } else { throw (age); } } catch (int no) { cout &…
Read moreopen Online C++ Compiler and enter below source code #include <iostream> using namespace std; int main () { int a,b,x ; cout << " enter values of a and b \n "; cin >> a; cin >> b; x=a-b; try { if( x != 0 ) { cout <<" Result a/x …
Read more