01 // Strukturierte Fehlerbehandlung
02 // Exceptionangaben
03 // Datei: sfehl07.cpp
04
05 #include <iostream.h>
06
07 int div_funktion (int a, int b) throw (char *)
08   {
09   if (b == 0)
10      throw (99L); // Nicht angemeldeter Auswurf
11    else          // führt zu: unexpected()
12      return a/b;
13   }
14
15 int main ()
16 {
17 cout << "\x1b[H\x1b[2J";  // Bildschirm löschen
18 try
19   {
20  cout<<"\nErgebnis: "<<div_funktion(10,0)<<endl;
21   }
22 catch (char * cp)
23   {
24   cerr << "\nFehlerbehandlung.\n" <<cp<<endl;
25   }
26 return 0;
27 }
28

Bild 18-14  Festlegen der möglichen Exceptions