Witam. Czytałem w jaki sposób w c++ przechwycić wyjątek i stosownie się zachować. Postanowiłem przejść od słów do czynów, ale coś nie wyszło. Po wykryciu wyjątku program miał wyświetlić w konsoli kreślony tekst. Jednak zamiast tekstu program przerywa swoje działanie z takim komunikatem:
int main()
{
class p1won{};
class p2won{};
srand(time(NULL));
int round = 13;
Dice d1;
Dice d2;
game_info();
while (round <= 13)
{
srand(time(NULL));
d1.random_numbers(0);
d1.random_again(0,0);
system("cls");
cout << players_tab[0].name << endl;
system("cls");
d2.random_numbers(1);
d2.random_again(1,1);
system("cls");
cout << players_tab[1].name << endl;
system("cls");
if (round == 13)
{
cout << "Player: " << players_tab[0].name << ", " << "Points: " << players_tab[0].points << endl;
cout << "Player: " << players_tab[1].name << ", " << "Points: " << players_tab[1].points << endl;
try
{
if (players_tab[0].points > players_tab[1].points)
{
//cout << "Player: " << players_tab[0].name << "Won !" << endl;
throw p1won();
}
else
{
throw p2won();
//cout << "Player: " << players_tab[1].name << "Won !" << endl;
}
}//try
catch (p1won())
{
cout << "Player: " << players_tab[0].name << "Won !" << endl;
}
catch (p2won())
{
cout << "Player: " << players_tab[1].name << "Won !" << endl;
}
}//if
round++;
}
system("pause");
return 0;
}