From 789ff25f27a6536903c3444589213041128ffe75 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 10 Jun 2014 15:12:12 -0700 Subject: [PATCH] Remove some exceptions not used for much of anything --- libaegisub/common/option_visit.cpp | 17 ++++----- libaegisub/common/option_visit.h | 4 -- libaegisub/include/libaegisub/option.h | 1 - libaegisub/include/libaegisub/option_value.h | 7 +--- src/command/tool.cpp | 4 +- src/dialog_translation.cpp | 2 +- src/dialog_translation.h | 2 +- tests/tests/option.cpp | 40 ++++++++++---------- 8 files changed, 34 insertions(+), 43 deletions(-) diff --git a/libaegisub/common/option_visit.cpp b/libaegisub/common/option_visit.cpp index 7c2f5bacc..7cb9f25fd 100644 --- a/libaegisub/common/option_visit.cpp +++ b/libaegisub/common/option_visit.cpp @@ -37,12 +37,11 @@ ConfigVisitor::ConfigVisitor(OptionValueMap &val, const std::string &member_name { } -template 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 ConfigVisitor::ReadArray(json::Array const& src, st for (json::Object const& obj : src) { if (obj.size() != 1) { - Error("Invalid array member"); + Error("Invalid array member"); return nullptr; } if (obj.begin()->first != array_type) { - Error("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 ConfigVisitor::ReadArray(json::Array const& src, st void ConfigVisitor::Visit(const json::Array& array) { if (array.empty()) { - Error("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("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(array, array_type)); else - Error("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("Attempt to read null value"); + Error("Attempt to read null value"); } void ConfigVisitor::AddOptionValue(std::unique_ptr&& opt) { @@ -148,7 +147,7 @@ void ConfigVisitor::AddOptionValue(std::unique_ptr&& 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 diff --git a/libaegisub/common/option_visit.h b/libaegisub/common/option_visit.h index 529db404a..529a02055 100644 --- a/libaegisub/common/option_visit.h +++ b/libaegisub/common/option_visit.h @@ -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 void Error(const char *message); template diff --git a/libaegisub/include/libaegisub/option.h b/libaegisub/include/libaegisub/option.h index e2a9d56dd..ddf35d6f2 100644 --- a/libaegisub/include/libaegisub/option.h +++ b/libaegisub/include/libaegisub/option.h @@ -35,7 +35,6 @@ namespace agi { DEFINE_EXCEPTION(OptionError, Exception); DEFINE_EXCEPTION(OptionErrorNotFound, OptionError); -DEFINE_EXCEPTION(OptionErrorDuplicateKey, OptionError); class OptionValue; diff --git a/libaegisub/include/libaegisub/option_value.h b/libaegisub/include/libaegisub/option_value.h index f9fda0fd9..0c088a6be 100644 --- a/libaegisub/include/libaegisub/option_value.h +++ b/libaegisub/include/libaegisub/option_value.h @@ -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 diff --git a/src/command/tool.cpp b/src/command/tool.cpp index a94d24cb2..4c7a7e3d4 100644 --- a/src/command/tool.cpp +++ b/src/command/tool.cpp @@ -206,8 +206,8 @@ struct tool_translation_assistant final : public Command { try { c->dialog->ShowModal(c); } - catch (agi::Exception const& e) { - wxMessageBox(to_wx(e.GetMessage())); + catch (DialogTranslation::NothingToTranslate const&) { + wxMessageBox(_("There is nothing to translate in the file.")); } } }; diff --git a/src/dialog_translation.cpp b/src/dialog_translation.cpp index b9b59d928..c5fb4ffb8 100644 --- a/src/dialog_translation.cpp +++ b/src/dialog_translation.cpp @@ -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(); diff --git a/src/dialog_translation.h b/src/dialog_translation.h index 9901c1186..295a0cbba 100644 --- a/src/dialog_translation.h +++ b/src/dialog_translation.h @@ -75,5 +75,5 @@ public: void Commit(bool next); void InsertOriginal(); - DEFINE_EXCEPTION(NothingToTranslate, agi::Exception);; + struct NothingToTranslate { }; }; diff --git a/tests/tests/option.cpp b/tests/tests/option.cpp index e5f588b14..7573c58b3 100644 --- a/tests/tests/option.cpp +++ b/tests/tests/option.cpp @@ -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); } }