[Rcpp-devel] idiom for creating an informative message for an exception

Douglas Bates bates at stat.wisc.edu
Thu Dec 2 22:15:45 CET 2010


In the lme4a package I mixed calls to Rf_error and throwing C++
exceptions.  This is causing problems and I plan to replace the calls
to Rf_error by exceptions so that there is a consistent approach.

Many of the calls to Rf_error take advantage of the fact the Rf_error
implicitly calls sprintf to create the error message.  Thus I have
calls like

	if (!d_x.size() == d_nrow * d_ncol)
	    ::Rf_error("%s: Dim = (%d, %d) is inconsistent with x.size() = %d",
		       "ddenseMatrix::ddenseMatrix", d_nrow, d_ncol, d_x.size());

Is there a similar idiom for creating an exception's "what" argument?
I imagine I could add std::strings and maybe use some iostreams or
something like that ...


More information about the Rcpp-devel mailing list