INTRODUCTION Overview Download and Install Documentation Publications REPOSITORY Libraries DEVELOPER Dev Guide Dashboard PEOPLE Contributors Users Project Download Mailing lists
|
gbxutilacfr/exceptions.h00001 /* 00002 * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics 00003 * http://gearbox.sf.net/ 00004 * Copyright (c) 2004-2008 Alex Brooks, Alexei Makarenko, Tobias Kaupp 00005 * 00006 * This distribution is licensed to you under the terms described in 00007 * the LICENSE file included in this distribution. 00008 * 00009 */ 00010 00011 #ifndef GBXUTILACFR_EXCEPTIONS_H 00012 #define GBXUTILACFR_EXCEPTIONS_H 00013 00014 /* 00015 * STRINGIZE macro converts an expression into a string-literal. 00016 * ERROR_INFO macro permits file-name and line-number data to be added to an error message. 00017 * 00018 * Adapted by Alex Brooks from Tim Bailey's version 2005. 00019 */ 00020 00021 #ifndef ERROR_MACROS_HPP_ 00022 #define ERROR_MACROS_HPP_ 00023 00024 #if defined(STRINGIZE_HELPER) || defined(STRINGIZE) || defined(ERROR_INFO) 00025 # error GbxUtilAcfr error macros have already been defined elsewhere 00026 #endif 00027 00028 #define STRINGIZE_HELPER(exp) #exp 00029 #define STRINGIZE(exp) STRINGIZE_HELPER(exp) 00030 00031 #define ERROR_INFO __FILE__, STRINGIZE(__LINE__) 00032 00033 #endif 00034 00035 #include <exception> 00036 #include <string> 00037 00038 namespace gbxutilacfr { 00039 00053 class Exception : public std::exception 00054 { 00055 public: 00056 Exception(const char *file, const char *line, const char *message); 00057 Exception(const char *file, const char *line, const std::string &message); 00058 00059 virtual ~Exception() throw(); 00060 00061 virtual const char* what() const throw() { return message_.c_str(); } 00062 00063 protected: 00064 void setMsg( const char *file, const char *line, const char *message ); 00065 00066 std::string message_; 00067 00068 private: 00069 const char *basename( const char *s ); 00070 }; 00071 00073 class HardwareException : public gbxutilacfr::Exception 00074 { 00075 public: 00076 HardwareException(const char *file, const char *line, const char *message) 00077 : Exception( file, line, message ) {}; 00078 HardwareException(const char *file, const char *line, const std::string &message) 00079 : Exception( file, line, message ) {}; 00080 }; 00081 00082 } // namespace 00083 00084 00085 #endif |