Rcpp Version 1.0.14
Loading...
Searching...
No Matches
exceptions.h
Go to the documentation of this file.
1// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2//
3// exceptions.h: Rcpp R/C++ interface class library -- exceptions
4//
5// Copyright (C) 2017 James J Balamuta
6//
7// This file is part of Rcpp.
8//
9// Rcpp is free software: you can redistribute it and/or modify it
10// under the terms of the GNU General Public License as published by
11// the Free Software Foundation, either version 2 of the License, or
12// (at your option) any later version.
13//
14// Rcpp is distributed in the hope that it will be useful, but
15// WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License
20// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21
22#ifndef Rcpp__exceptionscpp11__h
23#define Rcpp__exceptionscpp11__h
24
25// Required for std::forward
26#include <utility>
27
28namespace Rcpp {
29
30#define RCPP_ADVANCED_EXCEPTION_CLASS(__CLASS__, __WHAT__) \
31class __CLASS__ : public std::exception { \
32 public: \
33 __CLASS__( ) throw() : message( std::string(__WHAT__) + "." ){} \
34 __CLASS__( const std::string& message ) throw() : \
35 message( std::string(__WHAT__) + ": " + message + "."){} \
36 template <typename... Args> \
37 __CLASS__( const char* fmt, Args&&... args ) throw() : \
38 message( tfm::format(fmt, std::forward<Args>(args)... ) ){} \
39 virtual ~__CLASS__() throw(){} \
40 virtual const char* what() const throw() { return message.c_str(); } \
41 private: \
42 std::string message; \
43};
44
45template <typename... Args>
46inline void warning(const char* fmt, Args&&... args ) {
47 Rf_warning("%s", tfm::format(fmt, std::forward<Args>(args)... ).c_str());
48}
49
50template <typename... Args>
51inline void NORET stop(const char* fmt, Args&&... args) {
52 throw Rcpp::exception( tfm::format(fmt, std::forward<Args>(args)... ).c_str() );
53}
54
55} // namespace Rcpp
56#endif
#define NORET
Definition headers.h:82
Rcpp API.
Definition algo.h:28
void NORET stop(const std::string &message)
Definition exceptions.h:117
T as(SEXP x)
Definition as.h:151
void warning(const std::string &message)
Definition exceptions.h:113
void format(std::ostream &out, const char *fmt)
Definition tinyformat.h:996