[Rcpp-devel] Raise a condition
romain at r-enthusiasts.com
Thu Jun 19 07:13:32 CEST 2014
Le 19 juin 2014 à 03:05, Dirk Eddelbuettel <edd at debian.org> a écrit :
> 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.
Would be relatively easy to add an overload to stop
so that it handles other things besides strings.
The confines of the R interface is not the problem here.
More information about the Rcpp-devel