54 #ifndef CA_MGM_EXCEPTION_HPP
55 #define CA_MGM_EXCEPTION_HPP
57 #include "ca-mgm/config.h"
61 namespace CA_MGM_NAMESPACE
69 Exception(
const char* file,
int line,
const char* msg,
70 int errorCode,
const Exception *otherException = 0);
81 virtual const char* type()
const;
86 virtual const char* getMessage()
const;
91 virtual std::string getFullMessage()
const;
96 const char* getFile()
const;
104 int getErrorCode()
const;
109 virtual const char* what()
const throw();
118 namespace ExceptionDetail
122 template <
typename exType>
125 static exType
simple(
char const * file,
int line,
int errnum)
127 return exType(file, line, ::
strerror(errnum), errnum);
130 template <
typename Mtype>
131 static exType
format(
char const * file,
int line,
132 Mtype
const & msg,
int errnum)
134 return format(file, line, msg.c_str(), errnum);
137 static exType
format(
char const * file,
int line,
138 char const * msg,
int errnum)
140 return exType(file, line,
str::form(
"%s: %d(%s)", msg, errnum, ::
strerror(errnum)).c_str(), errnum);
152 #define CA_MGM_DECLARE_EXCEPTION2(NAME, BASE) \
153 class NAME##Exception : public BASE \
156 NAME##Exception(const char* file, int line, const char* msg, int errorCode = 0, const ca_mgm::Exception* otherException = 0); \
157 virtual ~NAME##Exception() throw(); \
158 virtual const char* type() const; \
167 #define CA_MGM_DECLARE_EXCEPTION(NAME) CA_MGM_DECLARE_EXCEPTION2(NAME, ca_mgm::Exception)
177 #define CA_MGM_DEFINE_EXCEPTION2(NAME, BASE) \
178 NAME##Exception::NAME##Exception(const char* file, int line, const char* msg, int errorCode, const ::ca_mgm::Exception* otherException) \
179 : BASE(file, line, msg, errorCode, otherException) {} \
180 NAME##Exception::~NAME##Exception() throw() { } \
181 const char* NAME##Exception::type() const { return #NAME "Exception"; }\
191 #define CA_MGM_DEFINE_EXCEPTION(NAME) CA_MGM_DEFINE_EXCEPTION2(NAME, ca_mgm::Exception)
200 #define CA_MGM_THROW(exType, msg) throw exType(__FILE__, __LINE__, (msg))
209 #define CA_MGM_THROW_SUBEX(exType, msg, subex) \
210 throw exType(__FILE__, __LINE__, (msg), -1, &(subex))
218 #define CA_MGM_THROW_ERR(exType, msg, err) \
219 throw exType(__FILE__, __LINE__, (msg), (err))
225 #define CA_MGM_THROW_ERRNO(exType) CA_MGM_THROW_ERRNO1(exType, errno)
233 #define CA_MGM_THROW_ERRNO1(exType, errnum) \
234 throw ::ca_mgm::ExceptionDetail::Errno< exType >::simple(__FILE__, __LINE__, (errnum))
242 #define CA_MGM_THROW_ERRNO_MSG(exType, msg) \
243 CA_MGM_THROW_ERRNO_MSG1(exType, (msg), errno)
252 #define CA_MGM_THROW_ERRNO_MSG1(exType, msg, errnum) \
253 throw ::ca_mgm::ExceptionDetail::Errno< exType >:: \
254 format(__FILE__, __LINE__, (msg), (errnum))
Definition: Exception.hpp:64
std::string strerror(int errno_r)
int m_errorCode
Definition: Exception.hpp:115
static exType format(char const *file, int line, Mtype const &msg, int errnum)
Definition: Exception.hpp:131
int m_line
Definition: Exception.hpp:113
Definition: Exception.hpp:123
char * m_file
Definition: Exception.hpp:112
std::ostream & operator<<(std::ostream &ostr, const PathName &path)
unsigned const BUFSZ
Definition: Exception.hpp:120
char * m_msg
Definition: Exception.hpp:114
static exType simple(char const *file, int line, int errnum)
Definition: Exception.hpp:125
std::string form(const char *format,...)
static exType format(char const *file, int line, char const *msg, int errnum)
Definition: Exception.hpp:137
#define CA_MGM_DECLARE_EXCEPTION(NAME)
Definition: Exception.hpp:167