Skip to content

Commit fb4b14d

Browse files
committed
Add macros to throw a java exception from an rcl error
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
1 parent 646839c commit fb4b14d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

rcljava_common/include/rcljava_common/exceptions.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,31 @@
3737
*/
3838
#define RCLJAVA_COMMON_EXCEPTION_CHECK(env) RCLJAVA_COMMON_EXCEPTION_CHECK_X(env, return )
3939

40+
/// Call \ref rcljava_throw_rclexception if \a ret is not RCL_RET_OK,
41+
/// and execute \a error_statement in that case.
42+
/**
43+
* \param env a JNIEnv pointer, used to throw a java exception from the rcl error.
44+
* \param ret rcl_ret_t error that will be checked.
45+
* \param message error message that will be passed to the thrown exception.
46+
* \param error_statement statement executed if ret was not RCL_RET_OK.
47+
*/
48+
#define RCLJAVA_COMMON_THROW_FROM_RCL_X(env, ret, message, error_statement) \
49+
do { \
50+
if (RCL_RET_OK != ret) { \
51+
rcljava_common::exception::rcljava_throw_rclexception(env, ret, message); \
52+
error_statement; \
53+
} \
54+
} while (0)
55+
56+
/// Call \ref rcljava_throw_rclexception if \a ret is not RCL_RET_OK and return.
57+
/**
58+
* \param env a JNIEnv pointer, used to check for exceptions.
59+
* \param ret rcl_ret_t error that will be checked.
60+
* \param message error message that will be passed to the thrown exception.
61+
*/
62+
#define RCLJAVA_COMMON_THROW_FROM_RCL(env, ret, message) \
63+
RCLJAVA_COMMON_THROW_FROM_RCL_X(env, ret, message, return )
64+
4065
namespace rcljava_common
4166
{
4267
namespace exceptions

0 commit comments

Comments
 (0)