From 6ef0f065a6d401fc90a4dc18153101ba97bff95b Mon Sep 17 00:00:00 2001 From: jacob1 Date: Thu, 17 May 2018 20:52:40 -0400 Subject: [PATCH] fix .what methods on exceptions --- src/client/GameSave.h | 16 +++++++-------- src/gui/interface/RichLabel.cpp | 8 ++++---- src/gui/search/SearchView.cpp | 33 +++++++++++++++++++++++++------ src/gui/search/SearchView.h | 2 +- src/gui/tags/TagsModelException.h | 8 ++++---- 5 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/client/GameSave.h b/src/client/GameSave.h index de59763bad..e24325b850 100644 --- a/src/client/GameSave.h +++ b/src/client/GameSave.h @@ -15,24 +15,24 @@ struct ParseException: public std::exception { enum ParseResult { OK = 0, Corrupt, WrongVersion, InvalidDimensions, InternalError, MissingElement }; - String message; + ByteString message; ParseResult result; public: - ParseException(ParseResult result, String message_): message(message_), result(result) {} - const char * what() const throw() + ParseException(ParseResult result, String message): message(message.ToUtf8()), result(result) {} + const char * what() const throw() override { - return message.ToUtf8().c_str(); + return message.c_str(); } ~ParseException() throw() {} }; struct BuildException: public std::exception { - String message; + ByteString message; public: - BuildException(String message_): message(message_) {} - const char * what() const throw() + BuildException(String message): message(message.ToUtf8()) {} + const char * what() const throw() override { - return message.ToUtf8().c_str(); + return message.c_str(); } ~BuildException() throw() {} }; diff --git a/src/gui/interface/RichLabel.cpp b/src/gui/interface/RichLabel.cpp index 3177af2419..7405bb17ad 100644 --- a/src/gui/interface/RichLabel.cpp +++ b/src/gui/interface/RichLabel.cpp @@ -10,12 +10,12 @@ using namespace ui; struct RichTextParseException: public std::exception { - String message; + ByteString message; public: - RichTextParseException(String message_ = String("Parse error")): message(message_) {} - const char * what() const throw() + RichTextParseException(String message = String("Parse error")): message(message.ToUtf8()) {} + const char * what() const throw() override { - return message.ToUtf8().c_str(); + return message.c_str(); } ~RichTextParseException() throw() {}; }; diff --git a/src/gui/search/SearchView.cpp b/src/gui/search/SearchView.cpp index e37658e2fe..2c2c5a3959 100644 --- a/src/gui/search/SearchView.cpp +++ b/src/gui/search/SearchView.cpp @@ -27,7 +27,11 @@ SearchView::SearchView(): nextButton = new ui::Button(ui::Point(WINDOWW-52, WINDOWH-18), ui::Point(50, 16), String("Next ") + 0xE015); previousButton = new ui::Button(ui::Point(2, WINDOWH-18), ui::Point(50, 16), 0xE016 + String(" Prev")); tagsLabel = new ui::Label(ui::Point(270, WINDOWH-18), ui::Point(WINDOWW-540, 16), "\boPopular Tags:"); - motdLabel = new ui::RichLabel(ui::Point(51, WINDOWH-18), ui::Point(WINDOWW-102, 16), Client::Ref().GetMessageOfTheDay()); + try + { + motdLabel = new ui::RichLabel(ui::Point(51, WINDOWH-18), ui::Point(WINDOWW-102, 16), Client::Ref().GetMessageOfTheDay()); + } + catch (std::exception e) { } class PageNumAction : public ui::TextboxAction { @@ -253,7 +257,18 @@ SearchView::SearchView(): void SearchView::NotifyMessageOfTheDay(Client * sender) { - motdLabel->SetText(sender->GetMessageOfTheDay()); + if (motdLabel) + { + try + { + motdLabel->SetText(sender->GetMessageOfTheDay()); + } + catch (std::exception e) + { + motdLabel = nullptr; + } + } + } void SearchView::doSearch() @@ -467,8 +482,11 @@ void SearchView::NotifyTagListChanged(SearchModel * sender) vector > tags = sender->GetTagList(); - RemoveComponent(motdLabel); - motdLabel->SetParentWindow(NULL); + if (motdLabel) + { + RemoveComponent(motdLabel); + motdLabel->SetParentWindow(NULL); + } RemoveComponent(tagsLabel); tagsLabel->SetParentWindow(NULL); @@ -499,8 +517,11 @@ void SearchView::NotifyTagListChanged(SearchModel * sender) AddComponent(tagsLabel); tagsLabel->Position.Y = tagYOffset-16; - AddComponent(motdLabel); - motdLabel->Position.Y = tagYOffset-30; + if (motdLabel) + { + AddComponent(motdLabel); + motdLabel->Position.Y = tagYOffset-30; + } } class TagAction: public ui::ButtonAction diff --git a/src/gui/search/SearchView.h b/src/gui/search/SearchView.h index 93f7a94ff3..bef054536e 100644 --- a/src/gui/search/SearchView.h +++ b/src/gui/search/SearchView.h @@ -35,7 +35,7 @@ class SearchView: public ui::Window, public ClientListener ui::Label * pageLabel; ui::Label * pageCountLabel; ui::Label * tagsLabel; - ui::RichLabel * motdLabel; + ui::RichLabel * motdLabel = nullptr; ui::Button * sortButton; ui::Button * ownButton; ui::Spinner * loadingSpinner; diff --git a/src/gui/tags/TagsModelException.h b/src/gui/tags/TagsModelException.h index 350f6974e8..467153f313 100644 --- a/src/gui/tags/TagsModelException.h +++ b/src/gui/tags/TagsModelException.h @@ -4,11 +4,11 @@ #include "common/String.h" #include -class TagsModelException { - String message; +class TagsModelException : public std::exception { + ByteString message; public: - TagsModelException(String message_): message(message_) {}; - const char * what() const throw() { return message.ToUtf8().c_str(); }; + TagsModelException(String message): message(message.ToUtf8()) {}; + const char * what() const throw() override { return message.c_str(); }; ~TagsModelException() throw() {}; };