// // C++ Interface: g_exception // // Description: // defines a generic exception class // // Author: ICARE CGTD/UDEV Nicolas PASCAL , (C) 2009 // // Copyright: See COPYING file that comes with this distribution // // #ifndef G_EXCEPTION_H #define G_EXCEPTION_H #include using namespace std; #include "tools.h" /** * @class g_exception g_exception.h * @brief Generic exception class */ class g_exception : public exception { /** file where the exception has been raised */ string file; /** line where the exception has been raised */ int line; /** exception message */ string msg; public: /** * @brief constructor * @param file file of the exception * @param line line of the exception * @param msg message of the exception */ g_exception( const char* file = "", int line = -1, string msg = "" ) { set (file, line, msg); }; /** * @brief generic setter * @param file file of the exception * @param line line of the exception * @param msg message of the exception */ void set (const char* file = "", int line = -1, string msg = "") { this->file = file; this->line = line; this->msg = msg; }; /** * @brief destructor */ virtual ~g_exception() throw() { }; /** * @brief print the message of the exception * @return the description of the exception */ virtual const char * what() const throw() { string s ( file + string("[") + MyTools::to_string ( line ) + "] : " + msg ); return s.c_str(); } }; #endif