Skip to content

Commit

Permalink
Catch universal exception as well
Browse files Browse the repository at this point in the history
Fixes #47
  • Loading branch information
jimhester committed Jul 15, 2020
1 parent d4359d4 commit 8f663f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
@@ -1,5 +1,7 @@
# cpp11 (development version)

* The `END_CPP` macro now includes a `catch(...)` block to catch all C++ exceptions that do not inherit from `std::exception` (#47).

* Improve consistency of inserting NA values in r_string objects (#45)

* Added a `NEWS.md` file to track changes to the package.
Expand Down
29 changes: 16 additions & 13 deletions inst/include/cpp11/declarations.hpp
Expand Up @@ -33,17 +33,20 @@ T& unmove(T&& t) {
char buf[ERROR_SIZE] = ""; \
cpp11::release_existing_protections(); \
try {
#define END_CPP11 \
} \
catch (cpp11::unwind_exception & e) { \
err = e.token; \
} \
catch (std::exception & e) { \
strncpy(buf, e.what(), ERROR_SIZE - 1); \
} \
if (buf[0] != '\0') { \
Rf_error("%s", buf); \
} else if (err != R_NilValue) { \
CPP11_UNWIND \
} \
#define END_CPP11 \
} \
catch (cpp11::unwind_exception & e) { \
err = e.token; \
} \
catch (std::exception & e) { \
strncpy(buf, e.what(), ERROR_SIZE - 1); \
} \
catch (...) { \
strncpy(buf, "C++ error (unknown cause)", ERROR_SIZE - 1); \
} \
if (buf[0] != '\0') { \
Rf_error("%s", buf); \
} else if (err != R_NilValue) { \
CPP11_UNWIND \
} \
return R_NilValue;

0 comments on commit 8f663f6

Please sign in to comment.