Properly handle exceptions when saving the game

Add message boxes when an exception occurs while loading or saving the game
deque
scrawl 11 years ago
parent 5df9ff8e2c
commit 8b33c087e0

@ -149,6 +149,8 @@ void MWState::StateManager::endGame()
void MWState::StateManager::saveGame (const std::string& description, const Slot *slot) void MWState::StateManager::saveGame (const std::string& description, const Slot *slot)
{ {
try
{
ESM::SavedGame profile; ESM::SavedGame profile;
MWBase::World& world = *MWBase::Environment::get().getWorld(); MWBase::World& world = *MWBase::Environment::get().getWorld();
@ -234,6 +236,18 @@ void MWState::StateManager::saveGame (const std::string& description, const Slot
Settings::Manager::setString ("character", "Saves", Settings::Manager::setString ("character", "Saves",
slot->mPath.parent_path().filename().string()); slot->mPath.parent_path().filename().string());
}
catch (const std::exception& e)
{
std::stringstream error;
error << "Failed to save game: " << e.what();
std::cerr << error.str() << std::endl;
std::vector<std::string> buttons;
buttons.push_back("#{sOk}");
MWBase::Environment::get().getWindowManager()->messageBox(error.str(), buttons);
}
} }
void MWState::StateManager::quickSave (std::string name) void MWState::StateManager::quickSave (std::string name)
@ -371,10 +385,17 @@ void MWState::StateManager::loadGame (const Character *character, const Slot *sl
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
std::cerr << "failed to load saved game: " << e.what() << std::endl; std::stringstream error;
error << "Failed to load saved game: " << e.what();
std::cerr << error.str() << std::endl;
cleanup (true); cleanup (true);
MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_MainMenu); MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_MainMenu);
std::vector<std::string> buttons;
buttons.push_back("#{sOk}");
MWBase::Environment::get().getWindowManager()->messageBox(error.str(), buttons);
} }
} }

Loading…
Cancel
Save