[Rcpp-devel] C++ Throwing Exception.
To chime in about Romain's comment about recognizing more types. I would love a more robust exception handling. I think I already mentioned that but sometimes throwing a std::exception can be very expensive. something a little bit more robust would be very helpful. For example, with the discussion that we had a while back about catching the interrupt signal, I had to use an exception that did not inherit std::exception since it took sometimes over a minute to catch the interrupt. -Andrew
On Wed, Dec 22, 2010 at 5:25 AM, Dirk Eddelbuettel <edd at debian.org> wrote:
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.") );
Hth, Dirk
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
_______________________________________________ Rcpp-devel mailing list Rcpp-devel at lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20101222/36933cec/attachment.htm>