Remove some exceptions not used for much of anything

This commit is contained in:
Thomas Goyne 2014-06-10 15:12:12 -07:00
parent cfd2698b03
commit 789ff25f27
8 changed files with 34 additions and 43 deletions

View File

@ -37,12 +37,11 @@ ConfigVisitor::ConfigVisitor(OptionValueMap &val, const std::string &member_name
{
}
template<class ErrorType>
void ConfigVisitor::Error(const char *message) {
if (ignore_errors)
LOG_E("option/load/config_visitor") << "Error loading option from user configuration: " << message;
else
throw ErrorType(message);
throw OptionJsonValueError(message);
}
void ConfigVisitor::Visit(const json::Object& object) {
@ -62,11 +61,11 @@ std::unique_ptr<OptionValue> ConfigVisitor::ReadArray(json::Array const& src, st
for (json::Object const& obj : src) {
if (obj.size() != 1) {
Error<OptionJsonValueArray>("Invalid array member");
Error("Invalid array member");
return nullptr;
}
if (obj.begin()->first != array_type) {
Error<OptionJsonValueArray>("Attempt to insert value into array of wrong type");
Error("Attempt to insert value into array of wrong type");
return nullptr;
}
@ -78,13 +77,13 @@ std::unique_ptr<OptionValue> ConfigVisitor::ReadArray(json::Array const& src, st
void ConfigVisitor::Visit(const json::Array& array) {
if (array.empty()) {
Error<OptionJsonValueArray>("Cannot infer the type of an empty array");
Error("Cannot infer the type of an empty array");
return;
}
json::Object const& front = array.front();
if (front.size() != 1) {
Error<OptionJsonValueArray>("Invalid array member");
Error("Invalid array member");
return;
}
@ -101,7 +100,7 @@ void ConfigVisitor::Visit(const json::Array& array) {
else if (array_type == "color")
AddOptionValue(ReadArray<OptionValueListColor>(array, array_type));
else
Error<OptionJsonValueArray>("Array type not handled");
Error("Array type not handled");
}
void ConfigVisitor::Visit(const json::Integer& number) {
@ -130,7 +129,7 @@ void ConfigVisitor::Visit(const json::Boolean& boolean) {
}
void ConfigVisitor::Visit(const json::Null& null) {
Error<OptionJsonValueNull>("Attempt to read null value");
Error("Attempt to read null value");
}
void ConfigVisitor::AddOptionValue(std::unique_ptr<OptionValue>&& opt) {
@ -148,7 +147,7 @@ void ConfigVisitor::AddOptionValue(std::unique_ptr<OptionValue>&& opt) {
try {
values[name]->Set(opt.get());
}
catch (agi::OptionValueError const& e) {
catch (agi::InternalError const& e) {
if (ignore_errors)
LOG_E("option/load/config_visitor") << "Error loading option from user configuration: " << e.GetMessage();
else

View File

@ -26,9 +26,6 @@
namespace agi {
DEFINE_EXCEPTION(OptionJsonValueError, Exception);
DEFINE_EXCEPTION(OptionJsonValueArray, OptionJsonValueError);
DEFINE_EXCEPTION(OptionJsonValueSingle, OptionJsonValueError);
DEFINE_EXCEPTION(OptionJsonValueNull, OptionJsonValueError);
class ConfigVisitor final : public json::ConstVisitor {
/// Option map being populated
@ -42,7 +39,6 @@ class ConfigVisitor final : public json::ConstVisitor {
/// default value is changed to the new one
bool replace;
template<class ErrorType>
void Error(const char *message);
template<class OptionValueType>

View File

@ -35,7 +35,6 @@ namespace agi {
DEFINE_EXCEPTION(OptionError, Exception);
DEFINE_EXCEPTION(OptionErrorNotFound, OptionError);
DEFINE_EXCEPTION(OptionErrorDuplicateKey, OptionError);
class OptionValue;

View File

@ -27,9 +27,6 @@
#undef Bool
namespace agi {
DEFINE_EXCEPTION(OptionValueError, Exception);
DEFINE_EXCEPTION(OptionValueErrorInvalidType, OptionValueError);
/// Option type
/// No bitsets here.
enum class OptionType {
@ -67,8 +64,8 @@ class OptionValue {
throw agi::InternalError("Invalid option type");
}
OptionValueErrorInvalidType TypeError(OptionType type) const {
return OptionValueErrorInvalidType("Invalid type for option " + name + ": expected " + TypeToString(type) + ", got " + TypeToString(GetType()));
InternalError TypeError(OptionType type) const {
return InternalError("Invalid type for option " + name + ": expected " + TypeToString(type) + ", got " + TypeToString(GetType()));
}
template<typename T>

View File

@ -206,8 +206,8 @@ struct tool_translation_assistant final : public Command {
try {
c->dialog->ShowModal<DialogTranslation>(c);
}
catch (agi::Exception const& e) {
wxMessageBox(to_wx(e.GetMessage()));
catch (DialogTranslation::NothingToTranslate const&) {
wxMessageBox(_("There is nothing to translate in the file."));
}
}
};

View File

@ -159,7 +159,7 @@ DialogTranslation::DialogTranslation(agi::Context *c)
blocks = active_line->ParseTags();
if (bad_block(blocks[0])) {
if (!NextBlock())
throw NothingToTranslate(from_wx(_("There is nothing to translate in the file.")));
throw NothingToTranslate();
}
else
UpdateDisplay();

View File

@ -75,5 +75,5 @@ public:
void Commit(bool next);
void InsertOriginal();
DEFINE_EXCEPTION(NothingToTranslate, agi::Exception);;
struct NothingToTranslate { };
};

View File

@ -212,50 +212,50 @@ TEST_F(lagi_option, empty_array_decays_to_first_used_type) {
empty_arr_options opt;
EXPECT_NO_THROW(opt.Get("arr")->GetListBool());
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::InternalError);
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::InternalError);
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::InternalError);
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::InternalError);
}
{
empty_arr_options opt;
EXPECT_NO_THROW(opt.Get("arr")->GetListColor());
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::InternalError);
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::InternalError);
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::InternalError);
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::InternalError);
}
{
empty_arr_options opt;
EXPECT_NO_THROW(opt.Get("arr")->GetListDouble());
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::InternalError);
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::InternalError);
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::InternalError);
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::InternalError);
}
{
empty_arr_options opt;
EXPECT_NO_THROW(opt.Get("arr")->GetListInt());
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::InternalError);
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::InternalError);
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::InternalError);
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::InternalError);
}
{
empty_arr_options opt;
EXPECT_NO_THROW(opt.Get("arr")->GetListString());
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::OptionValueErrorInvalidType);
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::InternalError);
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::InternalError);
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::InternalError);
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::InternalError);
}
}