Skip to content

Commit

Permalink
fix .what methods on exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed May 18, 2018
1 parent aa389db commit 6ef0f06
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
16 changes: 8 additions & 8 deletions src/client/GameSave.h
Expand Up @@ -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() {}
};
Expand Down
8 changes: 4 additions & 4 deletions src/gui/interface/RichLabel.cpp
Expand Up @@ -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() {};
};
Expand Down
33 changes: 27 additions & 6 deletions src/gui/search/SearchView.cpp
Expand Up @@ -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
{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -467,8 +482,11 @@ void SearchView::NotifyTagListChanged(SearchModel * sender)

vector<pair<ByteString, int> > tags = sender->GetTagList();

RemoveComponent(motdLabel);
motdLabel->SetParentWindow(NULL);
if (motdLabel)
{
RemoveComponent(motdLabel);
motdLabel->SetParentWindow(NULL);
}

RemoveComponent(tagsLabel);
tagsLabel->SetParentWindow(NULL);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/gui/search/SearchView.h
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/gui/tags/TagsModelException.h
Expand Up @@ -4,11 +4,11 @@
#include "common/String.h"
#include <exception>

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() {};
};

Expand Down

0 comments on commit 6ef0f06

Please sign in to comment.