01 // Strukturierte Fehlerbehandlung
02 // Auswurf eines Fehlers, ohne Behandlung
03
// Datei: sfehl02.cpp
04
05 #include <iostream.h>
06
07 long teile (long
op1, long op2)
08 {
09 if (op2 == 0)
10 throw 99L; // Auswerfen long-Fehlers
11
return op1/op2;
12 }
14 int main ()
15 {
16 try
17 {
18 cout << "\x1b[H\x1b[2J";
19
cout<<"Strukturierte Fehlerbehandlung: Fall 2";
20 cout << "\nErgebnis
ist:" << teile (33L,0L);
21 }
22 catch (int i) // wird hier nicht erreicht
23
{
24 cerr << "\nFehlerbehandlung für int\n";
25 }
26 catch (char * cp) //
wird hier nicht erreicht
27 {
28 cerr << "\nFehlerbehandlung für char
*\n";
29 }
30 return 0;
31 }
32
|
Bild 18-8 Automatischer Abbruch durch terminate()
|