01 // Mehrstufige Fehlerbehandlung
02 // Datei: sfehl04.cpp
03
04 #include
<iostream.h>
06 int div_funktion (int a, int b)
07 {
08 try
09 {
10 if (b
== 0)
11 throw ("Division durch 0");
12 else
13 return a/b;
14 }
15 catch
(char * fehl)
16 {
17 cerr << "\nTeil 1 der Fehlerbehandlung \n"
18 <<
fehl << "\n" << endl;
19 throw; // Auswerfen momentane Fehlervariable
20
}
21 }
23 int main ()
24 {
25 cout << "\x1b[H\x1b[2J"; // Bildschirm löschen
26
try
27 {
28 cout<<"\nErgebnis: " <<div_funktion(10,0)<<endl;
29 }
30 catch
(char * cp)
31 {
32 cerr<<"\nTeil 2 der Behandlung.\n" <<cp<<endl;
33 }
34
return 0;
35 }
|
Bild 18-10 Mehrstufige Fehlerbehandlung
|