blob: ca8667328509026f1bf9ff11dd457ae4033bb1f2 (
plain)
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
40
41
42
43
|
/**************************************************************************
*
* Language: C++
* Purpose: Program to demonstrate the 'try', 'catch' and 'throw' statements.
* Author: M J Leslie
* Date: 21-Mar-98
*
* Compile: The following command was used to compile.
*
* g++ -fhandle-exceptions throw.cc -o throw
*
**************************************************************************/
#include <iostream.h> // For cout.
void ErrorFunc(int Error);
main()
{
ErrorFunc(0);
ErrorFunc(1);
}
void ErrorFunc(int Error)
{
try
{
cout << "Error code is " << Error << endl;
if (Error > 0 )
{
throw(Error); // This statement causes control to jump
// to the 'catch' statement
}
cout << "No Error occoured" << endl;
}
catch(int n)
{
cout << "Error number is " << n << endl;;
}
}
|