data_exception.hpp
Go to the documentation of this file.
00001 
00011 /*****************************************************************************
00012 ** Ifdefs
00013 *****************************************************************************/
00014 
00015 #ifndef ECL_EXCEPTIONS_DATA_EXCEPTION_HPP_
00016 #define ECL_EXCEPTIONS_DATA_EXCEPTION_HPP_
00017 
00018 /*****************************************************************************
00019 ** Disable check
00020 *****************************************************************************/
00021 
00022 #include <ecl/config/ecl.hpp>
00023 #ifndef ECL_DISABLE_EXCEPTIONS
00024 
00025 /*****************************************************************************
00026 ** Includes
00027 *****************************************************************************/
00028 
00029 #include <string>
00030 #include <sstream>
00031 #include <ecl/errors/handlers.hpp>
00032 #include "exception.hpp"
00033 #include <ecl/errors/macros.hpp>
00034 
00035 /*****************************************************************************
00036 ** Namespaces
00037 *****************************************************************************/
00038 
00039 namespace ecl {
00040 
00041 /*****************************************************************************
00042 ** Interface [DataException<Data>]
00043 *****************************************************************************/
00057 template <typename Data>
00058 class DataException : public Exception
00059 {
00060     public:
00061         DataException(const char* loc, ErrorFlag error, Data &d );
00062         DataException(const char* loc, ErrorFlag error, const std::string &msg, const Data &d );
00063         DataException(const char* loc, const DataException<Data> &e );
00064 
00065         virtual ~DataException() throw() {}
00066 
00067         const char* what() const throw();
00068 
00069         const ErrorFlag& flag() const { return error_type; } 
00070         const Data& data() const { return error_data; } 
00072     private:
00073         ErrorFlag error_type;
00074         Data error_data;
00075         std::string message;
00076 };
00077 
00078 /*****************************************************************************
00079  * Implementation
00080  ****************************************************************************/
00087 template <typename Data>
00088 DataException<Data>::DataException(const char* loc, ErrorFlag error, Data &d ) :
00089     Exception(loc),
00090     error_type(error),
00091     error_data(d)
00092 {}
00100 template <typename Data>
00101 DataException<Data>::DataException(const char* loc, ErrorFlag error, const std::string &msg, const Data &d ) :
00102     Exception(loc),
00103     error_type(error),
00104     error_data(d),
00105     message(msg)
00106 {}
00113 template <typename Data>
00114 DataException<Data>::DataException(const char* loc, const DataException<Data> &e ) :
00115     Exception(loc),
00116     error_type(e.flag()),
00117     error_data(e.data()),
00118     message(e.message)
00119 {
00120     location = std::string(loc) + "\n         : " + e.location;
00121 }
00127 template <typename Data>
00128 const char* DataException<Data>::what() const throw() {
00129 
00130     std::string what_msg;
00131 
00132     std::ostringstream stream;
00133     stream << "\n" << "Location : " << this->location << "\n";
00134     stream << "Flag     : " << Error(error_type).what() << "\n";
00135     if ( message.size() > 0 ) {
00136         stream << "Detail   : " << message << "\n";
00137     }
00138     stream << "Data     : " << error_data << "\n";
00139     what_msg = stream.str();
00140     return what_msg.c_str();
00141 }
00142 
00143 }; // namespace ecl
00144 
00145 #endif /* ECL_DISABLE_EXCEPTIONS */
00146 #endif /* ECL_EXCEPTIONS_DATA_EXCEPTION_HPP_*/


ecl_exceptions
Author(s): Daniel Stonier
autogenerated on Mon Jul 3 2017 02:21:15