[Rcpp-devel] Rcpp::stop crashes RGui and RStudio under Windows

Dirk Eddelbuettel edd at debian.org
Fri Nov 30 13:21:55 CET 2012


On 30 November 2012 at 08:44, Dieter Menne wrote:
| I tried the following under Windows 7, 64 bit, both RGui and RStudio
| 
| File "throw.cpp"
| 
| #include <Rcpp.h>
| using namespace Rcpp;
| // [[Rcpp::export]]
| int throwCpp(int nb) {
|   if (nb == 10) 
|     Rcpp::stop("Unexpected condition occurred");
|   return nb*2; // Just for testing the normal case }

A throw, and as I recall what was added recently as 'stop()' is a variant,
MUST gave a try/catch around it.  

If I write this as 

-----------------------------------------------------------------------------

#include <Rcpp.h>

using namespace Rcpp;

// [[Rcpp::export]]
int throwCpp(int nb) {
  try {
    if (nb == 10)
      Rcpp::stop("Unexpected condition occurred");
    return nb*2; // Just for testing the normal case }
  } catch( std::exception &ex ) {
    forward_exception_to_r( ex );
  } catch(...) { 
    ::Rf_error( "c++ exception (unknown reason)" ); 
  }
  return -1; // -Wall
}

-----------------------------------------------------------------------------

and then it all works (at least on my Linux box here)

R> sourceCpp("/tmp/dieter.cpp")
R> throwCpp(20)
[1] 40
R> throwCpp(10)
Error in throwCpp(10) : Unexpected condition occurred
R> throwCpp(10)
Error in throwCpp(10) : Unexpected condition occurred
R> throwCpp(10)
Error in throwCpp(10) : Unexpected condition occurred
R> 


Romain always wrote example with 'those' hidden and automatically added via
cxxfunction() et al; I always thought that to be dangerous as it does not
make clear that one needs try/catch. This would appear to strengthen my
case.

Dirk

| 
| 
| # R File
| library(Rcpp)
| sessionInfo()
| sourceCpp("throw.cpp")
| throwCpp(20) # works, just to test the setup
| throwCpp(10)
| 
| 
| When Rcpp::stop is hit, RGui and RStudio both crash. It's a really hard-hard
| crash, even killing the job is not possible, I have to restart Windows to
| get rid of the job.



| 
| Dieter
| 
| (apologies if this should be a repost, since I could not see it on the
| nabble-list after two days, I assumed there was something wrong with my
| first post).
| 
| 
| R version 2.15.2 (2012-10-26)
| Platform: x86_64-w64-mingw32/x64 (64-bit)
| 
| locale:
| [1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252   
| [3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
| [5] LC_TIME=German_Germany.1252    
| 
| attached base packages:
| [1] stats     graphics  grDevices utils     datasets  methods   base     
| 
| other attached packages:
| [1] Rcpp_0.10.1
| 
| 
| 
| 
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  


More information about the Rcpp-devel mailing list