Skip to content

Commit

Permalink
Imporve error hanling in read_custom_cards
Browse files Browse the repository at this point in the history
  • Loading branch information
APN-Pucky authored and APN-Pucky committed May 15, 2020
1 parent 334fdd6 commit f35983b
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,11 @@ std::unordered_map<unsigned, unsigned> read_custom_cards(Cards& all_cards, const
}
unsigned num_line(0);
cards_file.exceptions(std::ifstream::badbit);
try

while(cards_file && !cards_file.eof())
{
while(cards_file && !cards_file.eof())
{
try
{
std::string card_spec;
getline(cards_file, card_spec);
trim(card_spec);
Expand All @@ -379,23 +380,23 @@ std::unordered_map<unsigned, unsigned> read_custom_cards(Cards& all_cards, const
char mark{0};
parse_card_spec(all_cards, card_spec, card_id, card_num, num_sign, mark);
cards[card_id] = card_num;
}
}
catch (std::exception& e)
{
if (abort_on_missing)
{
throw e;
}
else
{
std::cerr << "Exception while parsing the custom cards file " << filename;
if (num_line > 0)
{
std::cerr << " at line " << num_line;
}
std::cerr << ": " << e.what() << ".\n";
}
}
catch (std::exception& e)
{
if (abort_on_missing)
{
throw e;
}
else
{
std::cerr << "Exception while parsing the custom cards file " << filename;
if (num_line > 0)
{
std::cerr << " at line " << num_line;
}
std::cerr << ": " << e.what() << ".\n";
}
}
}
return cards;
}
Expand Down

0 comments on commit f35983b

Please sign in to comment.