Skip to content

Commit db22521

Browse files
committed
Improve the macro
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
1 parent fb4b14d commit db22521

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

rcljava_common/include/rcljava_common/exceptions.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,21 @@
4040
/// Call \ref rcljava_throw_rclexception if \a ret is not RCL_RET_OK,
4141
/// and execute \a error_statement in that case.
4242
/**
43+
* The rcl error message will be added to \a base_message, and the rcl error state will be reset.
44+
*
4345
* \param env a JNIEnv pointer, used to throw a java exception from the rcl error.
4446
* \param ret rcl_ret_t error that will be checked.
4547
* \param message error message that will be passed to the thrown exception.
48+
* The complete error will be "${message}: ${rcl_error_string}".
49+
* \a message can be either a `const char *` or as `std::string`.
4650
* \param error_statement statement executed if ret was not RCL_RET_OK.
4751
*/
48-
#define RCLJAVA_COMMON_THROW_FROM_RCL_X(env, ret, message, error_statement) \
52+
#define RCLJAVA_COMMON_THROW_FROM_RCL_X(env, ret, base_message, error_statement) \
4953
do { \
5054
if (RCL_RET_OK != ret) { \
51-
rcljava_common::exception::rcljava_throw_rclexception(env, ret, message); \
55+
rcljava_common::exception::rcljava_throw_rclexception( \
56+
env, ret, static_cast<std::string>(message) + ": " + rcl_get_error_string().str); \
57+
rcl_reset_error();
5258
error_statement; \
5359
} \
5460
} while (0)

0 commit comments

Comments
 (0)