fix .what methods on exceptions

This commit is contained in:
jacob1 2018-05-17 20:52:40 -04:00
parent aa389dbbfd
commit 6ef0f065a6
5 changed files with 44 additions and 23 deletions

View File

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

View File

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

View File

@ -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<pair<ByteString, int> > 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

View File

@ -35,7 +35,7 @@ private:
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;

View File

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