<div dir="ltr"><div>Is it possible the issue here is ultimately just that our LongjumpException class doesn't inherit from std::exception?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Feb 6, 2022 at 9:18 AM Jeroen Ooms <<a href="mailto:jeroenooms@gmail.com">jeroenooms@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Sun, Feb 6, 2022 at 5:56 PM Dirk Eddelbuettel <<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>> wrote:<br>
><br>
><br>
> On 6 February 2022 at 17:40, Jeroen Ooms wrote:<br>
> | We can try to take V8 out of the equation, and see what actually<br>
> | causes the change. V8 uses (and tests!) the Rcpp feature to call an R<br>
> | function from C++. This behaves quite differently when using<br>
> | RCPP_UNWIND_PROTECT.<br>
> |<br>
> | Here is a dummy package to demonstrate this: <a href="https://github.com/jeroen/uptest" rel="noreferrer" target="_blank">https://github.com/jeroen/uptest</a><br>
> |<br>
> | The use case is simple: we want to call some R function from C++, and<br>
> | if it fails, catch the error message and deal with it in C++. I<br>
> | suspect there are more packages doing this, but perhaps they are not<br>
> | testing this case.<br>
> |<br>
> | The example from uptest above show that when we compile with<br>
> | RCPP_UNWIND_PROTECT, any R error is always printed directly to the<br>
> | console. Even if we catch the Rcpp::LongjumpException in C++, the R<br>
> | error still seems to bubble up (as Iñaki also noted). I think this is<br>
> | at least surprising.<br>
> |<br>
> | Then I am not sure what we do in C++ now with this<br>
> | Rcpp::LongjumpException if we catch it. We certainly don't want to<br>
> | unwind all the way in the middle of running the javascript code. The<br>
> | JavaScript code should be able to catch the R error, and continue<br>
> | running the script.<br>
> |<br>
> | Anyway if you want to make RCPP_UNWIND_PROTECT the default, I can<br>
> | obviously opt-out in V8, but as an Rcpp user I am not convinced this<br>
> | is an improvement.<br>
><br>
> Thanks for the feedback. I think there is an easy-to-understand, easy-to-make<br>
> error in a sample package (but kudos for creating one!).  Because Rcpp will<br>
> always wrap try/catch around the function you create with its mechanism, the<br>
> layer inside is redundant.  So I suggest the C++ function file becomes this<br>
> simpler / shorter variant:<br>
><br>
>   #include <Rcpp.h><br>
>   using namespace Rcpp;<br>
><br>
>   // [[Rcpp::export]]<br>
>   Rcpp::NumericVector call_r_from_rcpp() {<br>
>     Rcpp::Function callback = Rcpp::Environment::namespace_env("uptest")["callback"];<br>
>     callback();<br>
>     return Rcpp::NumericVector::create(42);<br>
>   }<br>
><br>
> which behaves fine for me in both cases.<br>
<br>
Well not really, this kind of misses my point that it the<br>
unwind-protect makes it impossible to meaningfully catch the R error<br>
in C++, handle it, and continue running the C++ code, without aborting<br>
the entire mission and throwing the user back in the console.<br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></blockquote></div></div>