@@ -97,10 +97,37 @@ namespace Rcpp {
9797 file_io_error (" file already exists" , file) {} // #nocov end
9898 };
9999
100+ // Variadic / code generated version of the warning and stop functions
101+ // can be found within the respective C++11 or C++98 exceptions.h
102+ // included below
103+ inline void warning (const std::string& message) { // #nocov start
104+ Rf_warning (message.c_str ());
105+ } // #nocov end
106+
107+ inline void NORET stop (const std::string& message) { // #nocov start
108+ throw Rcpp::exception (message.c_str ());
109+ } // #nocov end
110+
111+ } // namespace Rcpp
112+
113+
114+ // Determine whether to use variadic templated RCPP_ADVANCED_EXCEPTION_CLASS,
115+ // warning, and stop exception functions or to use the generated argument macro
116+ // based on whether the compiler supports c++11 or not.
117+ #if __cplusplus >= 201103L
118+ # include < Rcpp/exceptions/cpp11/exceptions.h>
119+ #else
120+ # include < Rcpp/exceptions/cpp98/exceptions.h>
121+ #endif
122+
123+ namespace Rcpp {
124+
100125 #define RCPP_EXCEPTION_CLASS (__CLASS__,__WHAT__ ) \
101126 class __CLASS__ : public std ::exception{ \
102127 public: \
103- __CLASS__ ( const std::string& message ) throw () : message( __WHAT__ ){} ; \
128+ __CLASS__ ( ) throw () : message( std::string(__WHAT__) + " ." ){} ; \
129+ __CLASS__ ( const std::string& message ) throw () : \
130+ message ( std::string(__WHAT__) + " : " + message + " ." ){} ; \
104131 virtual ~__CLASS__ () throw (){} ; \
105132 virtual const char * what () const throw() { return message.c_str () ; } \
106133 private: \
@@ -115,30 +142,35 @@ namespace Rcpp {
115142 virtual const char * what () const throw() { return __MESSAGE__ ; } \
116143 } ;
117144
118- RCPP_SIMPLE_EXCEPTION_CLASS (not_a_matrix, " not a matrix" )
119- RCPP_SIMPLE_EXCEPTION_CLASS (index_out_of_bounds, " index out of bounds" )
120- RCPP_SIMPLE_EXCEPTION_CLASS (parse_error, " parse error" )
121- RCPP_SIMPLE_EXCEPTION_CLASS (not_s4, " not an S4 object" ) // #nocov start
122- RCPP_SIMPLE_EXCEPTION_CLASS (not_reference, " not an S4 object of a reference class" )
123- RCPP_SIMPLE_EXCEPTION_CLASS (not_initialized, " C++ object not initialized (missing default constructor?)" )
124- RCPP_SIMPLE_EXCEPTION_CLASS (no_such_slot, " no such slot" )
125- RCPP_SIMPLE_EXCEPTION_CLASS (no_such_field, " no such field" )
126- RCPP_SIMPLE_EXCEPTION_CLASS (not_a_closure, " not a closure" )
127- RCPP_SIMPLE_EXCEPTION_CLASS (no_such_function, " no such function" )
128- RCPP_SIMPLE_EXCEPTION_CLASS (unevaluated_promise, " promise not yet evaluated" )
129-
130- RCPP_EXCEPTION_CLASS (not_compatible, message )
131- RCPP_EXCEPTION_CLASS (S4_creation_error, std::string(" error creating object of S4 class : " ) + message )
132- RCPP_EXCEPTION_CLASS (reference_creation_error, std::string(" error creating object of reference class : " ) + message )
133- RCPP_EXCEPTION_CLASS (no_such_binding, std::string(" no such binding : '" ) + message + " '" )
134- RCPP_EXCEPTION_CLASS (binding_not_found, std::string(" binding not found: '" ) + message + " '" )
135- RCPP_EXCEPTION_CLASS (binding_is_locked, std::string(" binding is locked: '" ) + message + " '" )
136- RCPP_EXCEPTION_CLASS (no_such_namespace, std::string(" no such namespace: '" ) + message + " '" )
137- RCPP_EXCEPTION_CLASS (function_not_exported, std::string(" function not exported: " ) + message)
138- RCPP_EXCEPTION_CLASS (eval_error, message ) // #nocov end
145+ RCPP_SIMPLE_EXCEPTION_CLASS (not_a_matrix, " Not a matrix." ) // #nocov start
146+ RCPP_SIMPLE_EXCEPTION_CLASS (parse_error, " Parse error." )
147+ RCPP_SIMPLE_EXCEPTION_CLASS (not_s4, " Not an S4 object." )
148+ RCPP_SIMPLE_EXCEPTION_CLASS (not_reference, " Not an S4 object of a reference class." )
149+ RCPP_SIMPLE_EXCEPTION_CLASS (not_initialized, " C++ object not initialized. (Missing default constructor?)" )
150+ RCPP_SIMPLE_EXCEPTION_CLASS (no_such_field, " No such field." ) // not used internally
151+ RCPP_SIMPLE_EXCEPTION_CLASS (no_such_function, " No such function." )
152+ RCPP_SIMPLE_EXCEPTION_CLASS (unevaluated_promise, " Promise not yet evaluated." )
153+
154+ // Promoted
155+ RCPP_EXCEPTION_CLASS (no_such_slot, " No such slot" )
156+ RCPP_EXCEPTION_CLASS (not_a_closure, " Not a closure" )
157+
158+ RCPP_EXCEPTION_CLASS (S4_creation_error, " Error creating object of S4 class" )
159+ RCPP_EXCEPTION_CLASS (reference_creation_error, " Error creating object of reference class" ) // not used internally
160+ RCPP_EXCEPTION_CLASS (no_such_binding, " No such binding" )
161+ RCPP_EXCEPTION_CLASS (binding_not_found, " Binding not found" )
162+ RCPP_EXCEPTION_CLASS (binding_is_locked, " Binding is locked" )
163+ RCPP_EXCEPTION_CLASS (no_such_namespace, " No such namespace" )
164+ RCPP_EXCEPTION_CLASS (function_not_exported, " Function not exported" )
165+ RCPP_EXCEPTION_CLASS (eval_error, " Evaluation error" ) // #nocov end
166+
167+ // Promoted
168+ RCPP_ADVANCED_EXCEPTION_CLASS (not_compatible, " Not compatible" )
169+ RCPP_ADVANCED_EXCEPTION_CLASS (index_out_of_bounds, " Index is out of bounds" )
139170
140- #undef RCPP_EXCEPTION_CLASS
141171 #undef RCPP_SIMPLE_EXCEPTION_CLASS
172+ #undef RCPP_EXCEPTION_CLASS
173+ #undef RCPP_ADVANCED_EXCEPTION_CLASS
142174
143175
144176namespace internal {
@@ -166,7 +198,7 @@ namespace internal {
166198 nth (expr, 2 ) == identity_fun &&
167199 nth (expr, 3 ) == identity_fun;
168200 }
169- }
201+ } // namespace internal
170202
171203} // namespace Rcpp
172204
@@ -281,117 +313,6 @@ inline SEXP exception_to_try_error( const std::exception& ex){
281313std::string demangle ( const std::string& name) ;
282314#define DEMANGLE (__TYPE__ ) demangle( typeid (__TYPE__).name() ).c_str()
283315
284- namespace Rcpp {
285-
286- inline void warning (const std::string& message) {
287- Rf_warning (message.c_str ());
288- }
289-
290- template <typename T1>
291- inline void warning (const char * fmt, const T1& arg1) {
292- Rf_warning ( tfm::format (fmt, arg1 ).c_str () );
293- }
294-
295- template <typename T1, typename T2>
296- inline void warning (const char * fmt, const T1& arg1, const T2& arg2) {
297- Rf_warning ( tfm::format (fmt, arg1, arg2 ).c_str () );
298- }
299-
300- template <typename T1, typename T2, typename T3>
301- inline void warning (const char * fmt, const T1& arg1, const T2& arg2, const T3& arg3) {
302- Rf_warning ( tfm::format (fmt, arg1, arg2, arg3).c_str () );
303- }
304-
305- template <typename T1, typename T2, typename T3, typename T4>
306- inline void warning (const char * fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4) {
307- Rf_warning ( tfm::format (fmt, arg1, arg2, arg3, arg4).c_str () );
308- }
309-
310- template <typename T1, typename T2, typename T3, typename T4, typename T5>
311- inline void warning (const char * fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5) {
312- Rf_warning ( tfm::format (fmt, arg1, arg2, arg3, arg4, arg5).c_str () );
313- }
314-
315- template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
316- inline void warning (const char * fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6) {
317- Rf_warning ( tfm::format (fmt, arg1, arg2, arg3, arg4, arg5, arg6).c_str () );
318- }
319-
320- template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
321- inline void warning (const char * fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7) {
322- Rf_warning ( tfm::format (fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7).c_str () );
323- }
324-
325- template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
326- inline void warning (const char * fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7, const T8& arg8) {
327- Rf_warning ( tfm::format (fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8).c_str () );
328- }
329-
330- template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
331- inline void warning (const char * fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7, const T8& arg8, const T9& arg9) {
332- Rf_warning ( tfm::format (fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9).c_str () );
333- }
334-
335- template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
336- inline void warning (const char * fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7, const T8& arg8, const T9& arg9, const T10& arg10) {
337- Rf_warning ( tfm::format (fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10).c_str () );
338- }
339-
340- inline void NORET stop (const std::string& message) { // #nocov start
341- throw Rcpp::exception (message.c_str ());
342- } // #nocov end
343-
344- template <typename T1>
345- inline void NORET stop (const char * fmt, const T1& arg1) {
346- throw Rcpp::exception ( tfm::format (fmt, arg1 ).c_str () );
347- }
348-
349- template <typename T1, typename T2>
350- inline void NORET stop (const char * fmt, const T1& arg1, const T2& arg2) {
351- throw Rcpp::exception ( tfm::format (fmt, arg1, arg2 ).c_str () );
352- }
353-
354- template <typename T1, typename T2, typename T3>
355- inline void NORET stop (const char * fmt, const T1& arg1, const T2& arg2, const T3& arg3) {
356- throw Rcpp::exception ( tfm::format (fmt, arg1, arg2, arg3).c_str () );
357- }
358-
359- template <typename T1, typename T2, typename T3, typename T4>
360- inline void NORET stop (const char * fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4) {
361- throw Rcpp::exception ( tfm::format (fmt, arg1, arg2, arg3, arg4).c_str () );
362- }
363-
364- template <typename T1, typename T2, typename T3, typename T4, typename T5>
365- inline void NORET stop (const char * fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5) {
366- throw Rcpp::exception ( tfm::format (fmt, arg1, arg2, arg3, arg4, arg5).c_str () );
367- }
368-
369- template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
370- inline void NORET stop (const char * fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6) {
371- throw Rcpp::exception ( tfm::format (fmt, arg1, arg2, arg3, arg4, arg5, arg6).c_str () );
372- }
373-
374- template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
375- inline void NORET stop (const char * fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7) {
376- throw Rcpp::exception ( tfm::format (fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7).c_str () );
377- }
378-
379- template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
380- inline void NORET stop (const char * fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7, const T8& arg8) {
381- throw Rcpp::exception ( tfm::format (fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8).c_str () );
382- }
383-
384- template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
385- inline void NORET stop (const char * fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7, const T8& arg8, const T9& arg9) {
386- throw Rcpp::exception ( tfm::format (fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9).c_str () );
387- }
388-
389- template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
390- inline void NORET stop (const char * fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7, const T8& arg8, const T9& arg9, const T10& arg10) {
391- throw Rcpp::exception ( tfm::format (fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10).c_str () );
392- }
393- }
394-
395316inline void forward_exception_to_r (const std::exception& ex){
396317 SEXP stop_sym = Rf_install ( " stop" ) ;
397318 Rcpp::Shield<SEXP> condition ( exception_to_r_condition (ex) );
0 commit comments