-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10.4.cpp
More file actions
36 lines (34 loc) · 682 Bytes
/
10.4.cpp
File metadata and controls
36 lines (34 loc) · 682 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// 10.4 wap in c++ show exception handling throwing exception int a - b where a > b
#include <iostream>
#include <stdexcept>
using namespace std;
int main()
{
int x, y;
bool m;
cout << "Enter value of x and y\n";
cin >> x >> y;
m = x > y ? true : false;
try
{
if (m)
{
cout << "Subtraction = " << x - y << endl;
}
else
{
throw("Subtraction not Possible");
}
}
catch (const char *E)
{
cout << "Caught an Exception\n";
cout << E << endl;
}
return 0;
}
// Output:
// Enter value of x and y
// 4 5
// Caught an Exception
// Subtraction not Possible