source: trunk/testapp/exceptions/basic.cpp

Last change on this file was 5442, checked in by sandervl, 24 years ago

* empty log message *

File size: 578 bytes
Line 
1// This example illustrates the basic use of
2// try, catch, and throw.
3
4#include <iostream.h>
5#include <stdlib.h>
6class IsZero { /* ... */ };
7void ZeroCheck( int i )
8{
9 if (i==0)
10 throw IsZero();
11}
12void main()
13{
14 double a;
15
16 cout << "Enter a number: ";
17 cin >> a;
18 try
19 {
20 ZeroCheck( a );
21 cout << "Reciprocal is " << 1.0/a << endl;
22 }
23 catch ( IsZero )
24 {
25 cout << "Zero input is not valid" << endl;
26 }
27 cout << "Finished." << endl;
28}
Note: See TracBrowser for help on using the repository browser.