Skip to content

Commit 646839c

Browse files
committed
Add macros to handle java exceptions
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
1 parent 29e3b84 commit 646839c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

rcljava_common/include/rcljava_common/exceptions.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@
1919

2020
#include "rcljava_common/visibility_control.hpp"
2121

22+
/// Execute \a error_statement if an exception has happened.
23+
/**
24+
* \param env a JNIEnv pointer, used to check for exceptions.
25+
* \param error_statement statement executed if an exception has happened.
26+
*/
27+
#define RCLJAVA_COMMON_EXCEPTION_CHECK_X(env, error_statement) \
28+
do { \
29+
if (env->ExceptionCheck()) { \
30+
error_statement; \
31+
} \
32+
} while (0)
33+
34+
/// Return from the current function if a java exception has happened.
35+
/**
36+
* \param env a JNIEnv pointer, used to check for exceptions.
37+
*/
38+
#define RCLJAVA_COMMON_EXCEPTION_CHECK(env) RCLJAVA_COMMON_EXCEPTION_CHECK_X(env, return )
39+
2240
namespace rcljava_common
2341
{
2442
namespace exceptions

0 commit comments

Comments
 (0)