| 364 | } |
| 365 | |
| 366 | inline SEXP string_to_try_error( const std::string& str){ |
| 367 | using namespace Rcpp; |
| 368 | |
| 369 | #ifndef RCPP_USING_UTF8_ERROR_STRING |
| 370 | Rcpp::Shield<SEXP> txt(Rf_mkString(str.c_str())); |
| 371 | Rcpp::Shield<SEXP> simpleErrorExpr(Rf_lang2(::Rf_install("simpleError"), txt)); |
| 372 | Rcpp::Shield<SEXP> tryError( Rf_mkString( str.c_str() ) ); |
| 373 | #else |
| 374 | Rcpp::Shield<SEXP> tryError( Rf_allocVector( STRSXP, 1 ) ) ; |
| 375 | SET_STRING_ELT( tryError, 0, Rf_mkCharLenCE( str.c_str(), str.size(), CE_UTF8 ) ); |
| 376 | Rcpp::Shield<SEXP> simpleErrorExpr( Rf_lang2(::Rf_install("simpleError"), tryError )); |
| 377 | #endif |
| 378 | |
| 379 | Rcpp::Shield<SEXP> simpleError( Rf_eval(simpleErrorExpr, R_GlobalEnv) ); |
| 380 | Rf_setAttrib( tryError, R_ClassSymbol, Rf_mkString("try-error") ) ; |
| 381 | Rf_setAttrib( tryError, Rf_install( "condition") , simpleError ) ; |
| 382 | |
| 383 | return tryError; // #nocov end |
| 384 | } |
| 385 | |
| 386 | inline SEXP exception_to_try_error( const std::exception& ex){ |
| 387 | return string_to_try_error(ex.what()); |
no test coverage detected