diff --git a/include/loot/exception/condition_syntax_error.h b/include/loot/exception/condition_syntax_error.h index 0bd0d39b..105e0a86 100644 --- a/include/loot/exception/condition_syntax_error.h +++ b/include/loot/exception/condition_syntax_error.h @@ -32,9 +32,9 @@ namespace loot { * @brief An exception class thrown if invalid syntax is encountered when * parsing a metadata condition. */ -class ConditionSyntaxError : public std::runtime_error { +class ConditionSyntaxError : public std::system_error { public: - using std::runtime_error::runtime_error; + using std::system_error::system_error; }; } diff --git a/include/loot/exception/error_categories.h b/include/loot/exception/error_categories.h index 42773fcc..710cfa5a 100644 --- a/include/loot/exception/error_categories.h +++ b/include/loot/exception/error_categories.h @@ -45,6 +45,14 @@ LOOT_API const std::error_category& esplugin_category(); * derived from std::error_category. */ LOOT_API const std::error_category& libloadorder_category(); + +/** + * @brief Get the error category that can be used to identify system_error + * exceptions that are due to loot condition interpreter errors. + * @returns A reference to the static object of unspecified runtime type, + * derived from std::error_category. + */ +LOOT_API const std::error_category& loot_condition_interpreter_category(); } #endif diff --git a/src/api/error_categories.cpp b/src/api/error_categories.cpp index b4bd9521..783d08c2 100644 --- a/src/api/error_categories.cpp +++ b/src/api/error_categories.cpp @@ -47,6 +47,16 @@ class libloadorder_category : public std::error_category { return code.category().name() == name(); } }; + +class loot_condition_interpreter_category : public std::error_category { + const char* name() const noexcept override { return "loot condition interpreter"; } + + std::string message(int) const override { return "loot condition interpreter error"; } + + bool equivalent(const std::error_code& code, int) const noexcept override { + return code.category().name() == name(); + } +}; } LOOT_API const std::error_category& esplugin_category() { @@ -58,4 +68,9 @@ LOOT_API const std::error_category& libloadorder_category() { static detail::libloadorder_category instance; return instance; } + +LOOT_API const std::error_category& loot_condition_interpreter_category() { + static detail::loot_condition_interpreter_category instance; + return instance; +} } diff --git a/src/api/metadata/condition_evaluator.cpp b/src/api/metadata/condition_evaluator.cpp index b65f7c1d..7f4330c6 100644 --- a/src/api/metadata/condition_evaluator.cpp +++ b/src/api/metadata/condition_evaluator.cpp @@ -29,6 +29,7 @@ #include "api/helpers/crc.h" #include "api/helpers/logging.h" #include "loot/exception/condition_syntax_error.h" +#include "loot/exception/error_categories.h" namespace loot { void HandleError(const std::string operation, int returnCode) { @@ -50,7 +51,7 @@ void HandleError(const std::string operation, int returnCode) { logger->error(err); } - throw ConditionSyntaxError(err); + throw ConditionSyntaxError(returnCode, loot_condition_interpreter_category(), err); } int mapGameType(GameType gameType) {