-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample33.cpp
More file actions
28 lines (23 loc) · 757 Bytes
/
example33.cpp
File metadata and controls
28 lines (23 loc) · 757 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
#include <iostream>
using namespace std;
// purpose: understanding try and catch blocks
// if we're dealing with an error in our try block it will throw an error
// when an error is thrown, it will direct to the catch block
// catch block in our case will print out the error number
// if momsAge is indeed older than the sonsAge, there will be no error, therefore the if statement will not execute, resulting in the catch statement not executing as well
int main()
{
try
{
int momsAge = 30;
int sonsAge = 34;
if (sonsAge > momsAge)
{
throw -1;
}
}
catch(int x)
{
cout << "son cannot be older than mother, ERROR NUMBER: " << x << endl;
}
}