Exception thrown when a node's tick() method throws an exception. Contains information about the node where the exception originated.
| 79 | /// Exception thrown when a node's tick() method throws an exception. |
| 80 | /// Contains information about the node where the exception originated. |
| 81 | class NodeExecutionError : public RuntimeError |
| 82 | { |
| 83 | public: |
| 84 | NodeExecutionError(TickBacktraceEntry failed_node, const std::string& original_message) |
| 85 | : RuntimeError(formatMessage(failed_node, original_message)) |
| 86 | , failed_node_(std::move(failed_node)) |
| 87 | , original_message_(original_message) |
| 88 | {} |
| 89 | |
| 90 | /// The node that threw the exception |
| 91 | [[nodiscard]] const TickBacktraceEntry& failedNode() const |
| 92 | { |
| 93 | return failed_node_; |
| 94 | } |
| 95 | |
| 96 | [[nodiscard]] const std::string& originalMessage() const |
| 97 | { |
| 98 | return original_message_; |
| 99 | } |
| 100 | |
| 101 | private: |
| 102 | TickBacktraceEntry failed_node_; |
| 103 | std::string original_message_; |
| 104 | |
| 105 | static std::string formatMessage(const TickBacktraceEntry& node, |
| 106 | const std::string& original_msg) |
| 107 | { |
| 108 | return StrCat("Exception in node '", node.node_path, "' [", node.registration_name, |
| 109 | "]: ", original_msg); |
| 110 | } |
| 111 | }; |
| 112 | |
| 113 | } // namespace BT |
| 114 |