Skip to content

Commit

Permalink
Add extra layers of try-catch for the unlikely of an exception while …
Browse files Browse the repository at this point in the history
…showing an error.
  • Loading branch information
CelticMinstrel committed Oct 9, 2020
1 parent af344d2 commit 93ca93d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
33 changes: 33 additions & 0 deletions src/gui/dialogs/wml_error.cpp
Expand Up @@ -171,6 +171,39 @@ namespace dialogs

REGISTER_DIALOG(wml_error)

static void display_error_in_error(const std::string& title, const std::string& original_error, const std::string& error_in_error)
{
std::string message = original_error;
message += "\n\n";
message += _("Additionally, the following error was encountered while handling this error:");
message += "\n\n";
message += error_in_error;
message += "\n\n";
message += _("Due to this subsequent error, the game will now exit.");
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title.c_str(), message.c_str(), nullptr);
}

void wml_error::display(const std::string& summary,
const std::string& post_summary,
const std::vector<std::string>& files,
const std::string& details)
{
bool have_error = false;
try {
wml_error error_dialog(summary, post_summary, files, details);
try {
error_dialog.show();
} catch(std::exception& error) {
have_error = true;
display_error_in_error("WML Error", error_dialog.report_, error.what());
throw;
}
} catch(std::exception& error) {
if(!have_error) display_error_in_error("WML Error", summary, error.what());
throw;
}
}

wml_error::wml_error(const std::string& summary,
const std::string& post_summary,
const std::vector<std::string>& files,
Expand Down
5 changes: 1 addition & 4 deletions src/gui/dialogs/wml_error.hpp
Expand Up @@ -43,10 +43,7 @@ class wml_error : public modal_dialog
static void display(const std::string& summary,
const std::string& post_summary,
const std::vector<std::string>& files,
const std::string& details)
{
wml_error(summary, post_summary, files, details).show();
}
const std::string& details);

/** The display function; see @ref modal_dialog for more information. */
static void display(const std::string& summary,
Expand Down

0 comments on commit 93ca93d

Please sign in to comment.