|
2 | 2 | // exceptions.h: Rcpp R/C++ interface class library -- exceptions |
3 | 3 | // |
4 | 4 | // Copyright (C) 2010 - 2020 Dirk Eddelbuettel and Romain Francois |
5 | | -// Copyright (C) 2021 - 2020 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar |
| 5 | +// Copyright (C) 2021 - 2024 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar |
| 6 | +// Copyright (C) 2025 Dirk Eddelbuettel, Romain Francois, Iñaki Ucar and James J Balamuta |
6 | 7 | // |
7 | 8 | // This file is part of Rcpp. |
8 | 9 | // |
@@ -170,19 +171,30 @@ struct LongjumpException { |
170 | 171 | } |
171 | 172 | }; |
172 | 173 |
|
173 | | -} // namespace Rcpp |
174 | | - |
| 174 | + #define RCPP_ADVANCED_EXCEPTION_CLASS(__CLASS__, __WHAT__) \ |
| 175 | + class __CLASS__ : public std::exception { \ |
| 176 | + public: \ |
| 177 | + __CLASS__( ) throw() : message( std::string(__WHAT__) + "." ){} \ |
| 178 | + __CLASS__( const std::string& message ) throw() : \ |
| 179 | + message( std::string(__WHAT__) + ": " + message + "."){} \ |
| 180 | + template <typename... Args> \ |
| 181 | + __CLASS__( const char* fmt, Args&&... args ) throw() : \ |
| 182 | + message( tfm::format(fmt, std::forward<Args>(args)... ) ){} \ |
| 183 | + virtual ~__CLASS__() throw(){} \ |
| 184 | + virtual const char* what() const throw() { return message.c_str(); } \ |
| 185 | + private: \ |
| 186 | + std::string message; \ |
| 187 | + }; |
175 | 188 |
|
176 | | -// Determine whether to use variadic templated RCPP_ADVANCED_EXCEPTION_CLASS, |
177 | | -// warning, and stop exception functions or to use the generated argument macro |
178 | | -// based on whether the compiler supports c++11 or not. |
179 | | -#if __cplusplus >= 201103L |
180 | | -# include <Rcpp/exceptions/cpp11/exceptions.h> |
181 | | -#else |
182 | | -# include <Rcpp/exceptions/cpp98/exceptions.h> |
183 | | -#endif |
| 189 | + template <typename... Args> |
| 190 | + inline void warning(const char* fmt, Args&&... args ) { |
| 191 | + Rf_warning("%s", tfm::format(fmt, std::forward<Args>(args)... ).c_str()); |
| 192 | + } |
184 | 193 |
|
185 | | -namespace Rcpp { |
| 194 | + template <typename... Args> |
| 195 | + inline void NORET stop(const char* fmt, Args&&... args) { |
| 196 | + throw Rcpp::exception( tfm::format(fmt, std::forward<Args>(args)... ).c_str() ); |
| 197 | + } |
186 | 198 |
|
187 | 199 | #define RCPP_EXCEPTION_CLASS(__CLASS__,__WHAT__) \ |
188 | 200 | class __CLASS__ : public std::exception{ \ |
|
0 commit comments