Next: Übungsprogramm: Das Greed-Game
Up: Templates, Exceptions sowie Pogrammierung
Previous: Vorgehensweise
#include <iostream.h>
int main()
{
int i;
cout << "Bitte Zahl eingeben:" << endl;
try
{
cin >>i;
if (i == 1) throw "ONE";
if (i == 3) throw "THREE";
if (i < 0) throw -1;
}
catch(char *str)
{
cout << "Exception:" << str << endl;
return 1;
}
catch(int j)
{
if ( j < 0 )
cout << "BELOW NULL" << endl;
}
}
// g++ -fhandle-exceptions
| © 1997 Gottfried Rudorfer, C++-AG, Lehrveranstaltungen, Abteilung für Angewandte Informatik, Wirtschaftsuniversität Wien, 3/19/1998 |