Hey guys,
I'm trying to figure out how to use exceptions, but I don't get it. Here is something I have in the constructor of one of my classes. Does this even make sense?
1 2 3 4 5 6 7 8 9 10 11
bool Engine::LoadMaps(string _source) {
string temp = "";
std::ifstream map_list(_source);
if (!map_list) // Does this throw make any sense?
throw std::exception("Error: Failed to open MapList.txt", 1);
while (getline(map_list, temp))
if (!maps.LoadMap(_source + '\\' + temp)) // This one as well?
throw std::exception("Error: Failed to load maps", 2);
map_list.close();
returntrue;
}
Hey, u'r missing 'try' and 'catch' blocks if u want to use exception handling tho I woulnd't recommend it here for stuff like ifstream since it already has ways for u to check to see if the stream is functional.
U should have ur written error msgs in the 'catch' blocks. This explains it all quite well: