22#ifndef Rcpp__exceptions__h
23#define Rcpp__exceptions__h
27#ifndef RCPP_DEFAULT_INCLUDE_CALL
28#define RCPP_DEFAULT_INCLUDE_CALL true
31#define GET_STACKTRACE() R_NilValue
65 std::ostringstream ostr;
73 message(std::string(
"no such environment: '") + name +
"'") {};
124namespace Rcpp {
namespace internal {
153#if (defined(R_VERSION) && R_VERSION >= R_Version(3, 5, 0))
156 Rf_error(
"Internal error: Rcpp longjump failed to resume");
179#if __cplusplus >= 201103L
187 #define RCPP_EXCEPTION_CLASS(__CLASS__,__WHAT__) \
188 class __CLASS__ : public std::exception{ \
190 __CLASS__( ) throw() : message( std::string(__WHAT__) + "." ){} ; \
191 __CLASS__( const std::string& message ) throw() : \
192 message( std::string(__WHAT__) + ": " + message + "." ){} ; \
193 virtual ~__CLASS__() throw(){} ; \
194 virtual const char* what() const throw() { return message.c_str() ; } \
196 std::string message ; \
199 #define RCPP_SIMPLE_EXCEPTION_CLASS(__CLASS__,__MESSAGE__) \
200 class __CLASS__ : public std::exception{ \
202 __CLASS__() throw() {} ; \
203 virtual ~__CLASS__() throw(){} ; \
204 virtual const char* what() const throw() { return __MESSAGE__ ; } \
234 #undef RCPP_SIMPLE_EXCEPTION_CLASS
235 #undef RCPP_EXCEPTION_CLASS
236 #undef RCPP_ADVANCED_EXCEPTION_CLASS
269 SEXP sys_calls_symbol = Rf_install(
"sys.calls");
276 while(CDR(cur) != R_NilValue) {
277 SEXP expr = CAR(cur);
291 #ifndef RCPP_USING_UTF8_ERROR_STRING
292 SET_STRING_ELT( res, 0, Rf_mkChar( ex_class.c_str() ) ) ;
294 SET_STRING_ELT( res, 0, Rf_mkCharLenCE( ex_class.c_str(), ex_class.size(), CE_UTF8 ) );
296 SET_STRING_ELT( res, 1, Rf_mkChar(
"C++Error" ) ) ;
297 SET_STRING_ELT( res, 2, Rf_mkChar(
"error" ) ) ;
298 SET_STRING_ELT( res, 3, Rf_mkChar(
"condition" ) ) ;
302inline SEXP
make_condition(
const std::string& ex_msg, SEXP call, SEXP cppstack, SEXP classes){
304 #ifndef RCPP_USING_UTF8_ERROR_STRING
305 SET_VECTOR_ELT( res, 0, Rf_mkString( ex_msg.c_str() ) ) ;
308 SET_STRING_ELT( ex_msg_rstring, 0, Rf_mkCharLenCE( ex_msg.c_str(), ex_msg.size(), CE_UTF8 ) );
309 SET_VECTOR_ELT( res, 0, ex_msg_rstring ) ;
311 SET_VECTOR_ELT( res, 1, call ) ;
312 SET_VECTOR_ELT( res, 2, cppstack ) ;
315 SET_STRING_ELT( names, 0, Rf_mkChar(
"message" ) ) ;
316 SET_STRING_ELT( names, 1, Rf_mkChar(
"call" ) ) ;
317 SET_STRING_ELT( names, 2, Rf_mkChar(
"cppstack" ) ) ;
318 Rf_setAttrib( res, R_NamesSymbol, names ) ;
319 Rf_setAttrib( res, R_ClassSymbol, classes ) ;
323template <
typename Exception>
326 std::string ex_class =
demangle(
typeid(ex).name() ) ;
328 std::string ex_class =
"<not available>";
330 std::string ex_msg = ex.what() ;
339 cppstack = R_NilValue;
342 SEXP condition = shelter(
make_condition( ex_msg, call, cppstack, classes) );
357 using namespace Rcpp;
359 #ifndef RCPP_USING_UTF8_ERROR_STRING
365 SET_STRING_ELT( tryError, 0, Rf_mkCharLenCE( str.c_str(), str.size(), CE_UTF8 ) );
366 Rcpp::Shield<SEXP> simpleErrorExpr( Rf_lang2(::Rf_install(
"simpleError"), tryError ));
370 Rf_setAttrib( tryError, R_ClassSymbol, Rf_mkString(
"try-error") ) ;
371 Rf_setAttrib( tryError, Rf_install(
"condition") , simpleError ) ;
380std::string
demangle(
const std::string& name) ;
382#define DEMANGLE(__TYPE__) demangle( typeid(__TYPE__).name() ).c_str()
387 SEXP stop_sym = Rf_install(
"stop" ) ;
390 Rf_eval( expr, R_GlobalEnv ) ;
394 SEXP stop_sym = Rf_install(
"stop" ) ;
397 Rf_eval( expr, R_GlobalEnv ) ;
self & field(const char *name_, T Class::*ptr, const char *docstring=0)
std::vector< std::string > stack
void copy_stack_trace_to_r() const
exception(const char *message_, bool include_call=RCPP_DEFAULT_INCLUDE_CALL)
bool include_call() const
void record_stack_trace()
exception(const char *message_, const char *, int, bool include_call=RCPP_DEFAULT_INCLUDE_CALL)
virtual const char * what() const
file_exists(const std::string &file)
virtual const char * what() const
std::string filePath() const
file_io_error(const std::string &msg, const std::string &file)
file_io_error(int code, const std::string &file)
file_io_error(const std::string &file)
file_not_found(const std::string &file)
no_such_env(const std::string &name)
virtual const char * what() const
#define RCPP_ADVANCED_EXCEPTION_CLASS(__CLASS__, __WHAT__)
void forward_rcpp_exception_to_r(const Rcpp::exception &ex)
void forward_exception_to_r(const std::exception &ex)
SEXP exception_to_try_error(const std::exception &ex)
#define RCPP_EXCEPTION_CLASS(__CLASS__, __WHAT__)
std::string demangle(const std::string &name)
SEXP string_to_try_error(const std::string &str)
SEXP get_exception_classes(const std::string &ex_class)
SEXP rcpp_exception_to_r_condition(const Rcpp::exception &ex)
SEXP make_condition(const std::string &ex_msg, SEXP call, SEXP cppstack, SEXP classes)
SEXP exception_to_r_condition(const std::exception &ex)
#define RCPP_SIMPLE_EXCEPTION_CLASS(__CLASS__, __MESSAGE__)
SEXP exception_to_condition_template(const Exception &ex, bool include_call)
#define RCPP_DEFAULT_INCLUDE_CALL
bool isLongjumpSentinel(SEXP x)
T as(SEXP x, ::Rcpp::traits::r_type_primitive_tag)
SEXP getLongjumpToken(SEXP sentinel)
void resumeJump(SEXP token)
bool is_Rcpp_eval_call(SEXP expr)
SEXP longjumpSentinel(SEXP token)
Promise_Impl< PreserveStorage > Promise
Function_Impl< PreserveStorage > Function
void NORET stop(const std::string &message)
LogicalVector in(const VectorBase< RTYPE, NA, T > &x, const VectorBase< RTYPE, RHS_NA, RHS_T > &table)
static std::string toString(const int i)
S4_Impl< PreserveStorage > S4
void warning(const std::string &message)
attribute_hidden SEXP rcpp_set_stack_trace(SEXP e)
attribute_hidden SEXP rcpp_get_stack_trace()
LongjumpException(SEXP token_)