Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch all exception handler #47

Closed
thk686 opened this issue Jul 15, 2020 · 3 comments
Closed

Catch all exception handler #47

thk686 opened this issue Jul 15, 2020 · 3 comments

Comments

@thk686
Copy link

thk686 commented Jul 15, 2020

First, thanks for this package! I've longed for a lean R to C++ interface for quite awhile.

It looks like the END_CPP11 macro lacks a catch-all exception handler. I was using a Boost library and wondering why I was getting aborts (it was not using std::exception). Was a catch(...){} block intentionally omitted?

cpp11::cpp_function('void test() { throw; }')
test() # abort

On OSX

R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> cpp11::cpp_function('void test() { throw; }')
> test() # abort
libc++abi.dylib: terminating
zsh: abort      R
@jimhester
Copy link
Member

Just because we hadn't yet encountered code that was issuing exceptions that didn't inherit from std::exception, but we can add this, thanks for opening the issue.

@jimhester
Copy link
Member

Ok this now should work how you assumed it would. Note I had to tweak your example slightly to throw an integer exception as throw; without any arguments is used to rethrow exceptions (and would skip even the universal try / catch block).

cpp11::cpp_function('void test() { throw 42; }')
test()
#> Error in test(): C++ error (unknown cause)

Created on 2020-07-15 by the reprex package (v0.3.0)

@thk686
Copy link
Author

thk686 commented Jul 16, 2020

Perfect. Thanks. (Yes, been a long time since I read through the legalese on throw/try/catch...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants