<div dir="ltr">And I'm seeing you pointed that out at the end of the README... so yes, we should probably just have our exception inherit from std::exception.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Feb 6, 2022 at 9:31 AM Dirk Eddelbuettel <<a href="mailto:edd@debian.org">edd@debian.org</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"><br>
On 6 February 2022 at 18:18, Jeroen Ooms wrote:<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>
I see. Well if we wanted to catch an R error on the R side, adding tryCatch<br>
still works. Here are your initial R function, renamed, and a new one:<br>
<br>
  callbackWithoutTry <- function() {<br>
    stop("Ouch from R")<br>
  }<br>
<br>
  callback <- function() {<br>
      tryCatch(stop("Ouch from R"),<br>
               error = function(e) { cat("Well that went south\n") },<br>
               finally = function(e) { cat("Normal end\n") } )<br>
  }<br>
<br>
This (under UNWIND_PROTECT) behaves:<br>
<br>
  edd@rob:/tmp/uptest(master)$ install.r .<br>
  * installing *source* package ‘uptest’ ...<br>
  ** using staged installation<br>
  ** libs<br>
  rm -f uptest.so RcppExports.o callback.o<br>
  ccache g++-11 -I"/usr/share/R/include" -DNDEBUG -DRCPP_USE_UNWIND_PROTECT -I'/usr/local/lib/R/site-library/Rcpp/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c RcppExports.cpp -o RcppExports.o<br>
  ccache g++-11 -I"/usr/share/R/include" -DNDEBUG -DRCPP_USE_UNWIND_PROTECT -I'/usr/local/lib/R/site-library/Rcpp/include'    -fpic  -g -O3 -Wall -pipe -pedantic  -c callback.cpp -o callback.o<br>
  ccache g++-11 -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -Wl,-z,relro -o uptest.so RcppExports.o callback.o -L/usr/lib/R/lib -lR<br>
  installing to /usr/local/lib/R/site-library/00LOCK-uptest/00new/uptest/libs<br>
  ** R<br>
  ** byte-compile and prepare package for lazy loading<br>
  ** help<br>
  *** installing help indices<br>
  ** building package indices<br>
  ** testing if installed package can be loaded from temporary location<br>
  ** checking absolute paths in shared objects and dynamic libraries<br>
  ** testing if installed package can be loaded from final location<br>
  ** testing if installed package keeps a record of temporary installation path<br>
  * DONE (uptest)<br>
  edd@rob:/tmp/uptest(master)$ R -q<br>
  > uptest::uptest()<br>
  Well that went south<br>
  [1] 42<br>
  > <br>
<br>
So this catches the stop(), enters a designates block and resumes in the C++<br>
function that called it all still returning the 42 we desired as The Answer.<br>
<br>
Dirk<br>
<br>
-- <br>
<a href="https://dirk.eddelbuettel.com" rel="noreferrer" target="_blank">https://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a><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>