Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f00be79

Browse files
all about throw
1 parent 64ffe4a commit f00be79

File tree

1 file changed

+39
-0
lines changed
  • Learn_CPP_Programming_Deep_Dive/Section 17 Exception_Handling/All_about_throw

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
class MyException
6+
{
7+
8+
};
9+
10+
11+
int division(int x, int y)
12+
{
13+
if( y == 0)
14+
{
15+
throw MyException(); // one can throw an int, a float, a double, a char , a string or a user defined type (class)
16+
}
17+
18+
return x/y;
19+
}
20+
21+
int main(void)
22+
{
23+
int a = 70, b = 0, c;
24+
25+
try
26+
{
27+
c = division(a,b);
28+
cout<<"The result is \t->\t"<<c<<endl;
29+
}
30+
catch(MyException e)
31+
{
32+
cout<<"Division by zero "<<endl;
33+
}
34+
35+
cout<<"End of program"<<endl;
36+
37+
38+
return 0;
39+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /