-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.cpp
More file actions
39 lines (32 loc) · 744 Bytes
/
exceptions.cpp
File metadata and controls
39 lines (32 loc) · 744 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
37
38
39
#include <iostream>
using namespace std;
static double
division (int a, int b) throw (const char *) // this is deprecated in c++=11
{
if( b == 0 )
{
throw "Division by zero condition!";
//TRYME
// throw 21; // Will invoke the std:unexpected and if no unexpected handler is set, will terminate the program
}
return (a/b);
}
static int
addition (int a, int b) // noexcept keyword replaces throw in c++-11
{
return a + b;
}
int main ()
{
int x = 50;
int y = 0;
double z = 0;
try {
z = division(x, y);
cout << z << endl;
}catch (const char* msg) {
cerr << "Exception thrown - " << msg << endl;
}
cout << "Addition x+y - " << addition (x,y) << endl;
return 0;
}