Rcpp Version 0.9.10
exceptions.h
Go to the documentation of this file.
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
00002 //
00003 // exceptions.h: Rcpp R/C++ interface class library -- exceptions
00004 //
00005 // Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
00006 //
00007 // This file is part of Rcpp.
00008 //
00009 // Rcpp is free software: you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 2 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // Rcpp is distributed in the hope that it will be useful, but
00015 // WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
00021 
00022 #ifndef Rcpp__exceptions__h
00023 #define Rcpp__exceptions__h
00024 
00025 namespace Rcpp{
00026 
00027 class exception : public std::exception {
00028 public:
00029     exception(const char* message_, const char* file, int line ) ;
00030     virtual ~exception() throw() ;
00031     virtual const char* what() const throw() ;
00032 private:
00033     std::string message ;
00034 } ;
00035 
00036 // simple helper
00037 static std::string toString(const int i) { 
00038     std::ostringstream ostr;
00039     ostr << i;
00040     return ostr.str();
00041 }
00042 
00043 class no_such_env : public std::exception{                                     
00044 public:                                                                        
00045     no_such_env( const std::string& name ) throw() : message( std::string("no such environment: '") + name + "'" ){} ;
00046     no_such_env( int pos ) throw() : message( "no environment in given position '" + toString(pos) + "'") {} ;
00047     virtual ~no_such_env() throw(){} ;                                         
00048     virtual const char* what() const throw(){ return message.c_str() ; } ;     
00049 private:                                                                       
00050     std::string message ;                                                      
00051 } ;
00052 
00053 
00054 #define RCPP_EXCEPTION_CLASS(__CLASS__,__WHAT__)                               \
00055 class __CLASS__ : public std::exception{                                       \
00056 public:                                                                        \
00057         __CLASS__( const std::string& message ) throw() : message( __WHAT__ ){} ;  \
00058         virtual ~__CLASS__() throw(){} ;                                           \
00059         virtual const char* what() const throw() ;                                 \
00060 private:                                                                       \
00061         std::string message ;                                                      \
00062 } ;
00063 
00064 #define RCPP_SIMPLE_EXCEPTION_CLASS(__CLASS__,__MESSAGE__)                     \
00065 class __CLASS__ : public std::exception{                                       \
00066 public:                                                                        \
00067         __CLASS__() throw() {} ;                                                   \
00068         virtual ~__CLASS__() throw(){} ;                                           \
00069         virtual const char* what() const throw() ;                                 \
00070 } ;
00071 
00072 RCPP_SIMPLE_EXCEPTION_CLASS(not_a_matrix, "not a matrix")
00073 RCPP_SIMPLE_EXCEPTION_CLASS(index_out_of_bounds, "index out of bounds")
00074 RCPP_SIMPLE_EXCEPTION_CLASS(parse_error, "parse error") 
00075 RCPP_SIMPLE_EXCEPTION_CLASS(not_s4, "not an S4 object")
00076 RCPP_SIMPLE_EXCEPTION_CLASS(not_reference, "not an S4 object of a reference class")
00077 RCPP_SIMPLE_EXCEPTION_CLASS(not_initialized, "C++ object not initialized (missing default constructor?)")
00078 RCPP_SIMPLE_EXCEPTION_CLASS(no_such_slot, "no such slot")
00079 RCPP_SIMPLE_EXCEPTION_CLASS(no_such_field, "no such field")
00080 RCPP_SIMPLE_EXCEPTION_CLASS(not_a_closure, "not a closure")
00081 RCPP_SIMPLE_EXCEPTION_CLASS(no_such_function, "no such function")
00082 RCPP_SIMPLE_EXCEPTION_CLASS(unevaluated_promise, "promise not yet evaluated")
00083 
00084 RCPP_EXCEPTION_CLASS(not_compatible, message )
00085 RCPP_EXCEPTION_CLASS(S4_creation_error, std::string("error creating object of S4 class : ") + message )
00086 RCPP_EXCEPTION_CLASS(reference_creation_error, std::string("error creating object of reference class : ") + message )
00087 RCPP_EXCEPTION_CLASS(no_such_binding, std::string("no such binding : '") + message + "'" )
00088 RCPP_EXCEPTION_CLASS(binding_not_found, std::string("binding not found: '") + message + "'" )
00089 RCPP_EXCEPTION_CLASS(binding_is_locked, std::string("binding is locked: '") + message + "'" )
00090 RCPP_EXCEPTION_CLASS(no_such_namespace, std::string("no such namespace: '") + message + "'" )
00091 RCPP_EXCEPTION_CLASS(eval_error, message )
00092 
00093 #undef RCPP_EXCEPTION_CLASS
00094 #undef RCPP_SIMPLE_EXCEPTION_CLASS
00095 
00096 } // namesapce Rcpp
00097 
00098 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Defines