Skip to content

Commit

Permalink
Made throw exceptions more understandable (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
CihatAltiparmak authored Sep 25, 2024
1 parent 74d114a commit e03cc17
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion yasmin/include/yasmin/blackboard/blackboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <map>
#include <mutex>
#include <string>
#include <exception>

#include "yasmin/blackboard/blackboard_value.hpp"
#include "yasmin/blackboard/blackboard_value_interface.hpp"
Expand All @@ -42,7 +43,7 @@ class Blackboard {
std::lock_guard<std::recursive_mutex> lk(this->mutex);

if (!this->contains(name)) {
throw "Element " + name + " does not exist in the blackboard";
throw std::runtime_error("Element " + name + " does not exist in the blackboard");
}

BlackboardValue<T> *b_value = (BlackboardValue<T> *)this->values.at(name);
Expand Down
3 changes: 2 additions & 1 deletion yasmin/src/yasmin/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <algorithm>
#include <string>
#include <vector>
#include <exception>

#include "yasmin/state.hpp"

Expand All @@ -30,7 +31,7 @@ State::operator()(std::shared_ptr<blackboard::Blackboard> blackboard) {

if (std::find(this->outcomes.begin(), this->outcomes.end(), outcome) ==
this->outcomes.end()) {
throw "Outcome (" + outcome + ") does not exist";
throw std::logic_error("Outcome (" + outcome + ") does not exist");
}

return outcome;
Expand Down
8 changes: 4 additions & 4 deletions yasmin/src/yasmin/state_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <map>
#include <memory>
#include <mutex>
#include <stdexcept>
#include <exception>
#include <string>
#include <vector>

Expand Down Expand Up @@ -101,8 +101,8 @@ StateMachine::execute(std::shared_ptr<blackboard::Blackboard> blackboard) {
// check outcome belongs to state
if (std::find(state->get_outcomes().begin(), state->get_outcomes().end(),
outcome) == this->outcomes.end()) {
throw "Outcome (" + outcome + ") is not register in state " +
this->current_state;
throw std::logic_error("Outcome (" + outcome + ") is not register in state " +
this->current_state);
}

// translate outcome using transitions
Expand Down Expand Up @@ -133,7 +133,7 @@ StateMachine::execute(std::shared_ptr<blackboard::Blackboard> blackboard) {

// outcome is not in the sm
} else {
throw "Outcome (" + outcome + ") without transition";
throw std::logic_error("Outcome (" + outcome + ") without transition");
}
}

Expand Down

0 comments on commit e03cc17

Please sign in to comment.