01 // Strukturierte Fehlerbehandlung
02 // Allgemeiner Fehlerbehandler
03
// Datei: sfehl05.cpp
04
05 #include <iostream.h>
06
07 int div_funktion
(int a, int b)
08 {
09 if (b == 0)
10 throw ("Division durch 0");
11 else
12
return a/b;
13 }
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 (int i)
23 {
24 err<<"\nFehlerbehandlung für int.\n"<<i<<endl;
25 }
26
catch (...) // fängt alle anderen Fehler
27 {
28 cerr<<"\nAllgemeine Fehlerbehandlung.\n"<<endl;
29
}
30 return 0;
31 }
32
|
Bild 18-11 Default Fehlerbehandlung
|