39#ifndef BLOCXX_EXCEPTION_HPP_INCLUDE_GUARD_
40#define BLOCXX_EXCEPTION_HPP_INCLUDE_GUARD_
41#include "blocxx/BLOCXX_config.h"
43#if defined(BLOCXX_NON_THREAD_SAFE_EXCEPTION_HANDLING)
65class BLOCXX_COMMON_API
Exception :
public std::exception
71 Exception(
const char* file,
int line,
const char* msg) BLOCXX_DEPRECATED;
88 Exception(
const char* file,
int line,
const char* msg,
int errorCode,
const Exception* otherException = 0,
int subClassId = UNKNOWN_SUBCLASS_ID);
90 Exception(
int subClassId,
const char* file,
int line,
const char* msg,
int errorCode,
91 const Exception* otherException = 0) BLOCXX_DEPRECATED;
106 void setSubClassId(
int subClassId);
107 void setErrorCode(
int errorCode);
112 static const int UNKNOWN_SUBCLASS_ID = -1;
113 static const int UNKNOWN_ERROR_CODE = -1;
119 virtual const char* type()
const;
124 virtual const char* getMessage()
const;
128 const char* getFile()
const;
130 int getSubClassId()
const;
134 const Exception* getSubException()
const;
140 int getErrorCode()
const;
145 virtual const char* what()
const throw();
164 virtual
void rethrow() const;
172 char* dupString(const
char* str);
182#if defined(BLOCXX_NON_THREAD_SAFE_EXCEPTION_HANDLING)
189namespace ExceptionDetail
202#pragma warning (push)
203#pragma warning (disable: 4251)
215 char const * get()
const;
223 template <
typename exType>
226 static exType
simple(
char const * file,
int line,
int errnum)
230 return exType(file, line, buf, errnum);
233 template <
typename Mtype>
234 static exType
format(
char const * file,
int line,
235 Mtype
const & msg,
int errnum)
237 return format(file, line, msg.c_str(), errnum);
240 static exType
format(
char const * file,
int line,
241 char const * msg,
int errnum)
244 return exType(file, line, fm.
get(), errnum);
254BLOCXX_COMMON_API std::ostream&
operator<< (std::ostream& os,
const Exception& e);
263#define BLOCXX_THROW(exType, msg) throw exType(__FILE__, __LINE__, (msg))
268#define BLOCXX_THROWL(exType, line, msg) throw exType(__FILE__, (line), (msg))
277#define BLOCXX_THROW_SUBEX(exType, msg, subex) \
278throw exType(__FILE__, __LINE__, (msg), \
279 ::BLOCXX_NAMESPACE::Exception::UNKNOWN_ERROR_CODE, &(subex))
287#define BLOCXX_THROW_ERR(exType, msg, err) \
288throw exType(__FILE__, __LINE__, (msg), (err))
295#define BLOCXX_THROW_ERRNO(exType) BLOCXX_THROW_ERRNO1(exType, errno)
303#define BLOCXX_THROW_ERRNO1(exType, errnum) \
304throw ::BLOCXX_NAMESPACE::ExceptionDetail::Errno< exType >::simple(__FILE__, __LINE__, (errnum))
312#define BLOCXX_THROW_ERRNO_MSG(exType, msg) \
313BLOCXX_THROW_ERRNO_MSG1(exType, (msg), errno)
322#define BLOCXX_THROW_ERRNO_MSG1(exType, msg, errnum) \
323throw ::BLOCXX_NAMESPACE::ExceptionDetail::Errno< exType >:: \
324 format(__FILE__, __LINE__, (msg), (errnum))
334#define BLOCXX_THROW_ERR_SUBEX(exType, msg, err, subex) \
335throw exType(__FILE__, __LINE__, (msg), (err), &(subex))
344#define BLOCXX_DECLARE_EXCEPTION2(NAME, BASE) \
345class NAME##Exception : public BASE \
348 NAME##Exception(const char* file, int line, const char* msg, int errorCode = ::BLOCXX_NAMESPACE::Exception::UNKNOWN_ERROR_CODE, const Exception* otherException = 0, int subClassId = ::BLOCXX_NAMESPACE::Exception::UNKNOWN_SUBCLASS_ID); \
349 virtual ~NAME##Exception() throw(); \
350 virtual const char* type() const; \
351 virtual NAME##Exception* clone() const; \
352 virtual void rethrow() const; \
366#define BLOCXX_DECLARE_APIEXCEPTION2(NAME, BASE, LINKAGE_SPEC) \
367class LINKAGE_SPEC NAME##Exception : public BASE \
370 NAME##Exception(const char* file, int line, const char* msg, int errorCode = ::BLOCXX_NAMESPACE::Exception::UNKNOWN_ERROR_CODE, const Exception* otherException = 0, int subClassId = ::BLOCXX_NAMESPACE::Exception::UNKNOWN_SUBCLASS_ID); \
371 virtual ~NAME##Exception() throw(); \
372 virtual const char* type() const; \
373 virtual NAME##Exception* clone() const; \
374 virtual void rethrow() const; \
386#define BLOCXX_DECLARE_EXCEPTION(NAME) BLOCXX_DECLARE_EXCEPTION2(NAME, ::BLOCXX_NAMESPACE::Exception)
396#define BLOCXX_DECLARE_APIEXCEPTION(NAME, LINKAGE_SPEC) BLOCXX_DECLARE_APIEXCEPTION2(NAME, ::BLOCXX_NAMESPACE::Exception, LINKAGE_SPEC)
406#define BLOCXX_DEFINE_EXCEPTION2(NAME, BASE) \
407NAME##Exception::NAME##Exception(const char* file, int line, const char* msg, int errorCode, const ::BLOCXX_NAMESPACE::Exception* otherException, int subClassId) \
408 : BASE(file, line, msg, errorCode, otherException, subClassId) {} \
409NAME##Exception::~NAME##Exception() throw() { } \
410NAME##Exception* NAME##Exception::clone() const { return new(std::nothrow) NAME##Exception(*this); } \
411const char* NAME##Exception::type() const { return #NAME "Exception"; }\
412void NAME##Exception::rethrow() const { throw *this; }
423#define BLOCXX_DEFINE_EXCEPTION_WITH_BASE_AND_ID_AUX(NAME, BASE, SUB_CLASS_ID) \
424NAME##Exception::NAME##Exception(const char* file, int line, const char* msg, int errorCode, const ::BLOCXX_NAMESPACE::Exception* otherException, int subClassId) \
425 : BASE(file, line, msg, errorCode, otherException, subClassId == ::BLOCXX_NAMESPACE::Exception::UNKNOWN_SUBCLASS_ID ? (SUB_CLASS_ID) : subClassId) {} \
426NAME##Exception::~NAME##Exception() throw() { } \
427NAME##Exception* NAME##Exception::clone() const { return new(std::nothrow) NAME##Exception(*this); } \
428const char* NAME##Exception::type() const { return #NAME "Exception"; } \
429void NAME##Exception::rethrow() const { throw *this; }
439#define BLOCXX_DEFINE_EXCEPTION(NAME) BLOCXX_DEFINE_EXCEPTION_WITH_BASE_AND_ID_AUX(NAME, ::BLOCXX_NAMESPACE::Exception, ::BLOCXX_NAMESPACE::Exception::UNKNOWN_SUBCLASS_ID)
449#define BLOCXX_DEFINE_EXCEPTION_WITH_ID(NAME) BLOCXX_DEFINE_EXCEPTION_WITH_BASE_AND_ID_AUX(NAME, ::BLOCXX_NAMESPACE::Exception, ::BLOCXX_NAMESPACE::ExceptionIds::NAME##ExceptionId)
460#define BLOCXX_DEFINE_EXCEPTION_WITH_BASE_AND_ID(NAME, BASE) BLOCXX_DEFINE_EXCEPTION_WITH_BASE_AND_ID_AUX(NAME, BASE, ::BLOCXX_NAMESPACE::ExceptionIds::NAME##ExceptionId)
NonRecursiveMutex m_mutex
The AutoPtr class provides a simple class for smart pointers to single objects (for multiple,...
This class is the base of all exceptions thrown by BloCxx code.
void portable_strerror_r(int errnum, char *buf, unsigned n)
ostream & operator<<(ostream &ostrm, const Bool &arg)
void swap(Array< T > &x, Array< T > &y)
static exType format(char const *file, int line, Mtype const &msg, int errnum)
static exType format(char const *file, int line, char const *msg, int errnum)
static exType simple(char const *file, int line, int errnum)