diff --git a/reading_machine/src/Action.cpp b/reading_machine/src/Action.cpp index 29081486964db22cb7f77bdc1f21e63ae653150d..7c496eebd632060e82d56be30ee0617d7e7f55e1 100644 --- a/reading_machine/src/Action.cpp +++ b/reading_machine/src/Action.cpp @@ -384,8 +384,18 @@ Action Action::assertIsEmpty(const std::string & colName, Config::Object object, auto appliable = [colName, object, relativeIndex](const Config & config, const Action &) { - auto lineIndex = config.getRelativeWordIndex(object, relativeIndex); - return util::isEmpty(config.getAsFeature(colName, lineIndex)); + try + { + if (!config.hasRelativeWordIndex(object, relativeIndex)) + return false; + auto lineIndex = config.getRelativeWordIndex(object, relativeIndex); + return util::isEmpty(config.getAsFeature(colName, lineIndex)); + } catch (std::exception & e) + { + util::myThrow(fmt::format("colName='{}' object='{}' relativeIndex='{}' {}", colName, object == Config::Object::Stack ? "Stack" : "Buffer", relativeIndex, e.what())); + } + + return false; }; return {Type::Check, apply, undo, appliable}; @@ -403,8 +413,18 @@ Action Action::assertIsNotEmpty(const std::string & colName, Config::Object obje auto appliable = [colName, object, relativeIndex](const Config & config, const Action &) { - auto lineIndex = config.getRelativeWordIndex(object, relativeIndex); - return !util::isEmpty(config.getAsFeature(colName, lineIndex)); + try + { + if (!config.hasRelativeWordIndex(object, relativeIndex)) + return false; + auto lineIndex = config.getRelativeWordIndex(object, relativeIndex); + return !util::isEmpty(config.getAsFeature(colName, lineIndex)); + } catch (std::exception & e) + { + util::myThrow(fmt::format("colName='{}' object='{}' relativeIndex='{}' {}", colName, object == Config::Object::Stack ? "Stack" : "Buffer", relativeIndex, e.what())); + } + + return false; }; return {Type::Check, apply, undo, appliable}; diff --git a/reading_machine/src/Transition.cpp b/reading_machine/src/Transition.cpp index 2e3400c23d4578f08dfcf6458328a58394b3d633..1a2ad12bdad2d496fd4449e25914bc0b54212013 100644 --- a/reading_machine/src/Transition.cpp +++ b/reading_machine/src/Transition.cpp @@ -81,19 +81,28 @@ void Transition::apply(Config & config) bool Transition::appliable(const Config & config) const { - if (!state.empty() && state != config.getState()) - return false; - - for (const Action & action : sequence) - if (!action.appliable(config, action)) + try + { + if (!state.empty() && state != config.getState()) return false; + for (const Action & action : sequence) + if (!action.appliable(config, action)) + return false; + } catch (std::exception & e) + { + util::myThrow(fmt::format("transition '{}' {}", name, e.what())); + } + return true; } int Transition::getCost(const Config & config) const { - return cost(config); + try {return cost(config);} + catch (std::exception & e) { util::myThrow(fmt::format("transition '{}' {}", name, e.what()));} + + return 0; } const std::string & Transition::getName() const