[Rcpp-devel] C++ Throwing Exception.
edd at debian.org
Wed Dec 22 13:25:24 CET 2010
On 22 December 2010 at 11:56, Cedric Ginestet wrote:
| throw("Matrix Index is lower than 0.");
| How can I modify my code in order to get the reason for the exception
| printed within R.
By passing a exception class that inherits from std::exception, see a C++
reference and / or the examples:
edd at max:~/svn/rcpp/pkg/Rcpp/inst/examples$ grep throw RcppInline/UncaughtExceptions.r
'throw std::range_error("boom"); return R_NilValue ; ',
Basically, don't just pass a string, pass a string _used as a ctor_ to the
exception you want to throw, e.g.
throw( std::runtime_error("Matrix Index is lower than 0.") );
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel