Skip to content

[R-pkg-devel] how to throw a C++ exception across modules

1 message · Joshua N Pritikin

#
OpenMx exports an API that I import into another package (gwsem) like 
this,

  aldp = R_GetCCallable("OpenMx", "AddLoadDataProvider")

gwsem registers some C++ classes through this API.

This works great until gwsem throws a C++ exception. OpenMx calls gwsem in 
a try-catch region. This works flawlessly on Linux. However, it seems to 
not work on Windows. win-builder.r-project.org complained,

** running tests for arch 'i386' ... [23s] ERROR
  Running 'testthat.R' [22s]
Running the tests in 'tests/testthat.R' failed.
Complete output:
  > library(testthat)
  > library(gwsem)
  Loading required package: OpenMx
  > 
  > test_check("gwsem")
  
  This application has requested the Runtime to terminate it in an unusual way.
  Please contact the application's support team for more information.
  terminate called after throwing an instance of 'std::runtime_error'
    what():  MxComputeLoadData: out of data (record 250 requested but only 199 in file)

What solution is recommended?

Thank you.