1
- // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
1
+ // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2
2
//
3
3
// exceptions.h: Rcpp R/C++ interface class library -- exceptions
4
4
//
5
- // Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
5
+ // Copyright (C) 2010 - 2017 Dirk Eddelbuettel and Romain Francois
6
6
//
7
7
// This file is part of Rcpp.
8
8
//
24
24
25
25
#define GET_STACKTRACE () stack_trace( __FILE__, __LINE__ )
26
26
27
- namespace Rcpp {
27
+ namespace Rcpp {
28
28
29
29
class exception : public std ::exception {
30
30
public:
31
- explicit exception (const char * message_) : message(message_){ rcpp_set_stack_trace (stack_trace ()); }
32
- exception (const char * message_, const char * file, int line ) : message(message_){
33
- rcpp_set_stack_trace ( stack_trace (file,line) ) ;
31
+ explicit exception (const char * message_) : message(message_) { // #nocov start
32
+ rcpp_set_stack_trace (stack_trace ());
33
+ }
34
+ exception (const char * message_, const char * file, int line) : message(message_) {
35
+ rcpp_set_stack_trace (stack_trace (file,line));
34
36
}
35
- virtual ~exception () throw (){}
37
+ virtual ~exception () throw () {}
36
38
virtual const char * what () const throw() {
37
- return message.c_str () ;
39
+ return message.c_str (); // #nocov end
38
40
}
39
41
private:
40
- std::string message ;
41
- } ;
42
+ std::string message;
43
+ };
42
44
43
45
// simple helper
44
- static std::string toString (const int i) {
46
+ static std::string toString (const int i) { // #nocov start
45
47
std::ostringstream ostr;
46
48
ostr << i;
47
- return ostr.str ();
49
+ return ostr.str (); // #nocov end
48
50
}
49
51
50
- class no_such_env : public std ::exception{
52
+ class no_such_env : public std ::exception {
51
53
public:
52
- no_such_env ( const std::string& name ) throw () : message( std::string(" no such environment: '" ) + name + " '" ){} ;
53
- no_such_env ( int pos ) throw () : message( " no environment in given position '" + toString(pos) + " '" ) {} ;
54
- virtual ~no_such_env () throw (){} ;
55
- virtual const char * what () const throw(){ return message.c_str () ; } ;
54
+ no_such_env (const std::string& name) throw () :
55
+ message (std::string(" no such environment: '" ) + name + " '" ) {};
56
+ no_such_env (int pos) throw () :
57
+ message (" no environment in given position '" + toString(pos) + " '" ) {};
58
+ virtual ~no_such_env () throw () {};
59
+ virtual const char * what () const throw() { return message.c_str (); };
56
60
private:
57
- std::string message ;
58
- } ;
61
+ std::string message;
62
+ };
59
63
60
64
class file_io_error : public std ::exception {
61
65
public:
62
- file_io_error (const std::string& file) throw () : message( std::string(" file io error: '" ) + file + " '" ), file(file) {} ;
63
- file_io_error (int code, const std::string& file) throw () : message( " file io error " + toString(code) + " : '" + file + " '" ), file(file) {} ;
64
- file_io_error (const std::string& msg, const std::string& file) throw () : message( msg + " : '" + file + " '" ), file(file) {} ;
65
- virtual ~file_io_error () throw (){} ;
66
- virtual const char * what () const throw(){ return message.c_str () ; } ;
67
- std::string filePath () const throw(){ return file ; } ;
66
+ file_io_error (const std::string& file) throw () : // #nocov start
67
+ message (std::string(" file io error: '" ) + file + " '" ), file(file) {};
68
+ file_io_error (int code, const std::string& file) throw () :
69
+ message (" file io error " + toString(code) + " : '" + file + " '" ), file(file) {};
70
+ file_io_error (const std::string& msg, const std::string& file) throw () :
71
+ message (msg + " : '" + file + " '" ), file(file) {};
72
+ virtual ~file_io_error () throw () {};
73
+ virtual const char * what () const throw() { return message.c_str (); };
74
+ std::string filePath () const throw() { return file; }; // #nocov end
68
75
private:
69
- std::string message ;
76
+ std::string message;
70
77
std::string file;
71
78
} ;
72
79
73
- class file_not_found : public file_io_error {
80
+ class file_not_found : public file_io_error { // #nocov start
74
81
public:
75
- file_not_found (const std::string& file) throw () : file_io_error(" file not found" , file) {}
82
+ file_not_found (const std::string& file) throw () :
83
+ file_io_error (" file not found" , file) {} // #nocov end
76
84
};
77
85
78
- class file_exists : public file_io_error {
86
+ class file_exists : public file_io_error { // #nocov start
79
87
public:
80
- file_exists (const std::string& file) throw () : file_io_error(" file already exists" , file) {}
88
+ file_exists (const std::string& file) throw () :
89
+ file_io_error (" file already exists" , file) {} // #nocov end
81
90
};
82
91
83
92
#define RCPP_EXCEPTION_CLASS (__CLASS__,__WHAT__ ) \
@@ -101,7 +110,7 @@ namespace Rcpp{
101
110
RCPP_SIMPLE_EXCEPTION_CLASS (not_a_matrix, " not a matrix" )
102
111
RCPP_SIMPLE_EXCEPTION_CLASS (index_out_of_bounds, " index out of bounds" )
103
112
RCPP_SIMPLE_EXCEPTION_CLASS (parse_error, " parse error" )
104
- RCPP_SIMPLE_EXCEPTION_CLASS (not_s4, " not an S4 object" )
113
+ RCPP_SIMPLE_EXCEPTION_CLASS (not_s4, " not an S4 object" ) // #nocov start
105
114
RCPP_SIMPLE_EXCEPTION_CLASS (not_reference, " not an S4 object of a reference class" )
106
115
RCPP_SIMPLE_EXCEPTION_CLASS (not_initialized, " C++ object not initialized (missing default constructor?)" )
107
116
RCPP_SIMPLE_EXCEPTION_CLASS (no_such_slot, " no such slot" )
@@ -118,15 +127,15 @@ namespace Rcpp{
118
127
RCPP_EXCEPTION_CLASS (binding_is_locked, std::string(" binding is locked: '" ) + message + " '" )
119
128
RCPP_EXCEPTION_CLASS (no_such_namespace, std::string(" no such namespace: '" ) + message + " '" )
120
129
RCPP_EXCEPTION_CLASS (function_not_exported, std::string(" function not exported: " ) + message)
121
- RCPP_EXCEPTION_CLASS (eval_error, message )
130
+ RCPP_EXCEPTION_CLASS (eval_error, message ) // #nocov end
122
131
123
132
#undef RCPP_EXCEPTION_CLASS
124
133
#undef RCPP_SIMPLE_EXCEPTION_CLASS
125
134
126
135
127
136
namespace internal {
128
137
129
- inline SEXP nth (SEXP s, int n) {
138
+ inline SEXP nth (SEXP s, int n) { // #nocov start
130
139
return Rf_length (s) > n ? (n == 0 ? CAR (s) : CAR (Rf_nthcdr (s, n))) : R_NilValue;
131
140
}
132
141
@@ -236,7 +245,7 @@ inline SEXP string_to_try_error( const std::string& str){
236
245
Rf_setAttrib ( tryError, R_ClassSymbol, Rf_mkString (" try-error" ) ) ;
237
246
Rf_setAttrib ( tryError, Rf_install ( " condition" ) , simpleError ) ;
238
247
239
- return tryError;
248
+ return tryError; // #nocov end
240
249
}
241
250
242
251
inline SEXP exception_to_try_error ( const std::exception& ex){
@@ -302,9 +311,9 @@ namespace Rcpp{
302
311
Rf_warning ( tfm::format (fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10).c_str () );
303
312
}
304
313
305
- inline void NORET stop (const std::string& message) {
314
+ inline void NORET stop (const std::string& message) { // #nocov start
306
315
throw Rcpp::exception (message.c_str ());
307
- }
316
+ } // #nocov end
308
317
309
318
template <typename T1>
310
319
inline void NORET stop (const char * fmt, const T1& arg1) {
0 commit comments