source: trunk/testapp/exceptions/ctrexc.cpp@ 5442

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

* empty log message *

File size: 556 bytes
Line 
1// This example illustrates constructors and
2// destructors in exception handling.
3
4#include <string.h> // needed for strcpy
5#include <iostream.h>
6class Matherr { public: char errname[30]; };
7class DivideByZero : public Matherr
8{
9public:
10 DivideByZero() {strcpy (errname, "Division by zero");}
11};
12double divide(double a, double b)
13{
14 if (b == 0) throw DivideByZero();
15 return a/b;
16}
17
18void main()
19{
20 double a=7,b=0;
21 try {divide (a,b);}
22 catch (Matherr xx)
23 {
24 cout << xx.errname << endl;
25 }
26}
27
Note: See TracBrowser for help on using the repository browser.