00001 /* 00002 Error class that incorporates additional information. 00003 00004 Copyright (C) 2010 - 2014 Christoph Haenisch 00005 00006 Chair of Medical Engineering (mediTEC) 00007 RWTH Aachen University 00008 Pauwelsstr. 20 00009 52074 Aachen 00010 Germany 00011 00012 See license.txt for more information. 00013 00014 Version 0.7.1 (2011-09-09) 00015 */ 00016 00022 #include <iostream> 00023 #include <sstream> 00024 #include <string> 00025 00026 #include "TRTK/ErrorObj.hpp" 00027 00028 00029 namespace TRTK 00030 { 00031 00032 00035 ErrorObj::ErrorObj() : error_code(0) 00036 { 00037 return; 00038 } 00039 00040 00047 ErrorObj::ErrorObj(const std::string error_message) : 00048 error_code(0), 00049 error_message(error_message) 00050 { 00051 return; 00052 } 00053 00054 00064 ErrorObj::ErrorObj(const std::string error_message, 00065 const std::string class_name) : 00066 error_code(0), 00067 class_name(class_name), 00068 error_message(error_message) 00069 { 00070 return; 00071 } 00072 00073 00089 ErrorObj::ErrorObj(const std::string error_message, 00090 const std::string class_name, 00091 const std::string function_name, 00092 const int error_code) : 00093 error_code(error_code), 00094 class_name(class_name), 00095 function_name(function_name), 00096 error_message(error_message) 00097 { 00098 return; 00099 } 00100 00101 00104 ErrorObj::~ErrorObj() throw() 00105 { 00106 return; 00107 } 00108 00109 00112 std::string ErrorObj::getClassName(void) const 00113 { 00114 return class_name; 00115 } 00116 00117 00120 int ErrorObj::getErrorCode(void) const 00121 { 00122 return error_code; 00123 } 00124 00125 00128 std::string ErrorObj::getErrorMessage(void) const 00129 { 00130 return error_message; 00131 } 00132 00133 00136 std::string ErrorObj::getFunctionName(void) const 00137 { 00138 return function_name; 00139 } 00140 00141 00142 // /** \return Returns the value stored in ErrorObj. */ 00143 // 00144 // boost::any ErrorObj::getValue(void) const 00145 // { 00146 // return value; 00147 // } 00148 // */ 00149 00150 00155 void ErrorObj::setClassName(const std::string class_name) 00156 { 00157 this->class_name = class_name; 00158 return; 00159 } 00160 00161 00166 void ErrorObj::setErrorCode(const int error_code) 00167 { 00168 this->error_code = error_code; 00169 return; 00170 } 00171 00172 00177 void ErrorObj::setErrorMessage(const std::string error_message) 00178 { 00179 this->error_message = error_message; 00180 return; 00181 } 00182 00183 00188 void ErrorObj::setFunctionName(const std::string function_name) 00189 { 00190 this->function_name = function_name; 00191 return; 00192 } 00193 00194 00195 // /** \param [in] value This can be an arbitrary value that is returned when 00196 // * calling getValue(). 00197 // */ 00198 // 00199 // void ErrorObj::setValue(const boost::any value) 00200 // { 00201 // this->value = value; 00202 // return; 00203 // } 00204 // */ 00205 00206 00216 const char * ErrorObj::what() const throw() 00217 { 00218 return what(NON_VERBOSE); 00219 } 00220 00221 00222 00231 const char * ErrorObj::what(const Verbosity verbose) const throw() 00232 { 00233 if(verbose) 00234 { 00235 std::stringstream ss; 00236 ss << "Error:" << std::endl; 00237 00238 if(class_name.size()) 00239 ss << " - Class: " << class_name << std::endl; 00240 00241 if(class_name.size()) 00242 ss << " - Function: " << function_name << std::endl; 00243 00244 if(class_name.size()) 00245 ss << " - Error message: " << error_message << std::endl; 00246 00247 if(class_name.size()) 00248 ss << " - Error Code: " << error_code << std::endl; 00249 00250 return ss.str().c_str(); 00251 } 00252 else 00253 { 00254 return error_message.c_str(); 00255 } 00256 } 00257 00258 00259 } // namespace TRTK 00260 00261 00262 // kate: indent-mode cstyle; space-indent on; indent-width 4;
Documentation generated by Doxygen