Write a program to use multiple catch statements.
#include<iostream> using namespace std; void test(int ); int main() { int val; cout << "Enter value = "; cin >> val; try { test(val); } catch(int t) { cout << "val = " << t << endl; } catch(...) { cout << "default" << endl; } return 0; } void test(int op) { if(op == 1) throw 10; if(op == 2) throw 'R'; if(op == 3) throw 34.5; }
Output
Enter value = 1 val = 10 Enter value = 2 default Enter value = 3 default