[Rcpp-devel] Raise a condition

Dirk Eddelbuettel edd at debian.org
Thu Jun 19 03:05:54 CEST 2014


On 18 June 2014 at 19:40, Tim Keitt wrote:
| 
| 
| 
| On Wed, Jun 18, 2014 at 6:26 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
| 
| 
|     Tim,
| 
|     Step back for a second and recognise that everything happens via
| 
|        SEXP .Call(SEXP a, SEXP b, ...)
| 
|     where R calls your C++ routine asynchronously.
| 
|     You can do tricks _within the subroutine that is called_ which is
|     essentially
|     what happens via the automatically-added try/catch block we have in C++.
|      And
|     Rcpp::stop() is just a shortcut for using those.
| 
| 
| Can I throw a condition (meaning an object inheriting class "condition") or am
| I limited to strings? If I throw a condition, will it be raised as such?

See eg Section 2.7 titled "Exception Handling" in my Springer book on Rcpp.
This is standard stuff, and we discussed the basics in the 2011 JSS paper.

You can throw anything that is subclassed from std::exception, and catch it
appropriately.  The default mechanism is to take the exception text and pass
it to R -- because, once again, passing a string is all we can do.  _Your_
code could course provide more complex things and keep them, and tickle (by
error codes) retrieval via other functions.

But again, the interface we are given by R is fixed.  You can only be
creative within the confines of that interface.

Dirk

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


More information about the Rcpp-devel mailing list