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 64ffe4a

Browse files
Throw and catch between different functions
1 parent 37ec54e commit 64ffe4a

File tree

1 file changed

+32
-0
lines changed
  • Learn_CPP_Programming_Deep_Dive/Section 17 Exception_Handling/Throw_Catch_Between_Functions

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int division(int x, int y)
6+
{
7+
if( y == 0)
8+
{
9+
throw 1;
10+
}
11+
12+
return x/y;
13+
}
14+
15+
int main(void)
16+
{
17+
int a = 12, b = 0, c;
18+
19+
try
20+
{
21+
c = division(a,b);
22+
cout<<c<<endl;
23+
}
24+
catch(int e)
25+
{
26+
cout<<"Division by zero\t->\t"<<e<<endl;
27+
}
28+
29+
cout<<"End of program."<<endl;
30+
31+
return 0;
32+
}

0 commit comments

Comments
(0)

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