add more context to exception message (#858)

* add more context to exception message

Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>

* fix linter warnings

Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
This commit is contained in:
Dirk Thomas 2019-09-19 13:15:19 -07:00 committed by GitHub
parent 9b47f36080
commit b6d18ccc81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
#include <limits> #include <limits>
#include <string>
#include <utility> #include <utility>
#include "rclcpp/clock.hpp" #include "rclcpp/clock.hpp"
@ -194,7 +195,10 @@ Duration
Time::operator-(const rclcpp::Time & rhs) const Time::operator-(const rclcpp::Time & rhs) const
{ {
if (rcl_time_.clock_type != rhs.rcl_time_.clock_type) { if (rcl_time_.clock_type != rhs.rcl_time_.clock_type) {
throw std::runtime_error("can't subtract times with different time sources"); throw std::runtime_error(
std::string("can't subtract times with different time sources [") +
std::to_string(rcl_time_.clock_type) + " != " +
std::to_string(rhs.rcl_time_.clock_type) + "]");
} }
if (rclcpp::sub_will_overflow(rcl_time_.nanoseconds, rhs.rcl_time_.nanoseconds)) { if (rclcpp::sub_will_overflow(rcl_time_.nanoseconds, rhs.rcl_time_.nanoseconds)) {