libcamgm
Classes | Namespaces | Macros | Variables
Exception.hpp File Reference

Common LiMaL exceptions. More...

#include "ca-mgm/config.h"
#include <ca-mgm/String.hpp>
#include <string.h>

Go to the source code of this file.

Classes

class  ca_mgm::Exception
 
struct  ca_mgm::ExceptionDetail::Errno< exType >
 
class  ca_mgm::MemoryException
 MemoryException class declaration. More...
 
class  ca_mgm::RuntimeException
 RuntimeException class declaration. More...
 
class  ca_mgm::OverflowException
 OverflowException class declaration. More...
 
class  ca_mgm::SyntaxException
 SyntaxException class declaration. More...
 
class  ca_mgm::ValueException
 ValueException class declaration. More...
 
class  ca_mgm::SystemException
 SystemException class declaration. More...
 
class  ca_mgm::OutOfBoundsException
 

Namespaces

 ca_mgm
 
 ca_mgm::ExceptionDetail
 

Macros

#define CA_MGM_DECLARE_EXCEPTION2(NAME, BASE)
 
#define CA_MGM_DECLARE_EXCEPTION(NAME)   CA_MGM_DECLARE_EXCEPTION2(NAME, ca_mgm::Exception)
 
#define CA_MGM_DEFINE_EXCEPTION2(NAME, BASE)
 
#define CA_MGM_DEFINE_EXCEPTION(NAME)   CA_MGM_DEFINE_EXCEPTION2(NAME, ca_mgm::Exception)
 
#define CA_MGM_THROW(exType, msg)   throw exType(__FILE__, __LINE__, (msg))
 
#define CA_MGM_THROW_SUBEX(exType, msg, subex)   throw exType(__FILE__, __LINE__, (msg), -1, &(subex))
 
#define CA_MGM_THROW_ERR(exType, msg, err)   throw exType(__FILE__, __LINE__, (msg), (err))
 
#define CA_MGM_THROW_ERRNO(exType)   CA_MGM_THROW_ERRNO1(exType, errno)
 
#define CA_MGM_THROW_ERRNO1(exType, errnum)   throw ::ca_mgm::ExceptionDetail::Errno< exType >::simple(__FILE__, __LINE__, (errnum))
 
#define CA_MGM_THROW_ERRNO_MSG(exType, msg)   CA_MGM_THROW_ERRNO_MSG1(exType, (msg), errno)
 
#define CA_MGM_THROW_ERRNO_MSG1(exType, msg, errnum)
 

Variables

unsigned const ca_mgm::ExceptionDetail::BUFSZ = 1024
 

Detailed Description

Common LiMaL exceptions.

This header file declares several common exception types.

BloCxx provides several macros helping to throw exceptions:

* #include <ca-mgm/Exception.hpp>
*
*
* "Can't do this and that");
*
* const int MY_INVALID_EMAIL_ERROR_NUMBER = 42;
* "Argument is not a valid email",
* MY_INVALID_EMAIL_ERROR_NUMBER);
*
* str::form("Syntax error in line %1", 42).c_str());
*
* try
* {
* do_something();
* }
* catch(const ca_mgm::Exception &subex)
* {
* "Bad things happened", subex);
* }
*

See BloCxx documentation for more informations.

Macro Definition Documentation

#define CA_MGM_DECLARE_EXCEPTION (   NAME)    CA_MGM_DECLARE_EXCEPTION2(NAME, ca_mgm::Exception)

Declare a new exception class named <NAME>Exception that derives from Exception This macro is typically used in a header file.

Parameters
NAMEThe name of the new class (Exception will be postfixed)
#define CA_MGM_DECLARE_EXCEPTION2 (   NAME,
  BASE 
)
Value:
class NAME##Exception : public BASE \
{ \
public: \
NAME##Exception(const char* file, int line, const char* msg, int errorCode = 0, const ca_mgm::Exception* otherException = 0); \
virtual ~NAME##Exception() throw(); \
virtual const char* type() const; \
};
Definition: Exception.hpp:64

Declare a new exception class named <NAME>Exception that derives from <BASE>. This macro is typically used in a header file.

Parameters
NAMEThe name of the new class (Exception will be postfixed)
BASEThe base class.
#define CA_MGM_DEFINE_EXCEPTION (   NAME)    CA_MGM_DEFINE_EXCEPTION2(NAME, ca_mgm::Exception)

Define a new exception class named <NAME>Exception that derives from Exception. The new class will use UNKNOWN_SUBCLASS_ID for the subclass id. Use this macro for internal implementation exceptions that don't have an id. This macro is typically used in a cpp file.

Parameters
NAMEThe name of the new class (Exception will be postfixed)
#define CA_MGM_DEFINE_EXCEPTION2 (   NAME,
  BASE 
)
Value:
NAME##Exception::NAME##Exception(const char* file, int line, const char* msg, int errorCode, const ::ca_mgm::Exception* otherException) \
: BASE(file, line, msg, errorCode, otherException) {} \
NAME##Exception::~NAME##Exception() throw() { } \
const char* NAME##Exception::type() const { return #NAME "Exception"; }\

Define a new exception class named <NAME>Exception that derives from <BASE>. The new class will use UNKNOWN_SUBCLASS_ID for the subclass id. This macro is typically used in a cpp file.

Parameters
NAMEThe name of the new class (Exception will be postfixed)
BASEThe base class.
#define CA_MGM_THROW (   exType,
  msg 
)    throw exType(__FILE__, __LINE__, (msg))

Throw an exception using FILE and LINE. If applicable, CA_MGM_THROW_ERR should be used instead of this macro.

Parameters
exTypeThe type of the exception
msgThe exception message. A string that will be copied.
#define CA_MGM_THROW_ERR (   exType,
  msg,
  err 
)    throw exType(__FILE__, __LINE__, (msg), (err))

Throw an exception using FILE and LINE.

Parameters
exTypeThe type of the exception
msgThe exception message. A string that will be copied.
errThe error code.
#define CA_MGM_THROW_ERRNO (   exType)    CA_MGM_THROW_ERRNO1(exType, errno)

Throw an exception using FILE, LINE, errno and strerror(errno)

Parameters
exTypeThe type of the exception; ctor must take file, line, message, and error code.
#define CA_MGM_THROW_ERRNO1 (   exType,
  errnum 
)    throw ::ca_mgm::ExceptionDetail::Errno< exType >::simple(__FILE__, __LINE__, (errnum))

Throw an exception using FILE, LINE, errnum and strerror(errnum)

Parameters
exTypeThe type of the exception; ctor must take file, line, message, and error code.
errnumThe errno value.
#define CA_MGM_THROW_ERRNO_MSG (   exType,
  msg 
)    CA_MGM_THROW_ERRNO_MSG1(exType, (msg), errno)

Throw an exception using FILE, LINE, errno and strerror(errno)

Parameters
exTypeThe type of the exception; ctor must take file, line, message, and error code.
msgThe exception message to use.
#define CA_MGM_THROW_ERRNO_MSG1 (   exType,
  msg,
  errnum 
)
Value:
throw ::ca_mgm::ExceptionDetail::Errno< exType >:: \
format(__FILE__, __LINE__, (msg), (errnum))

Throw an exception using FILE, LINE, errnum and strerror(errnum)

Parameters
exTypeThe type of the exception; ctor must take file, line, message, and error code.
msgThe exception message to use.
errnumThe errno value.
#define CA_MGM_THROW_SUBEX (   exType,
  msg,
  subex 
)    throw exType(__FILE__, __LINE__, (msg), -1, &(subex))

Throw an exception using FILE and LINE.

Parameters
exTypeThe type of the exception
msgThe exception message. A string that will be copied.
subexA sub-exception. A pointer to it will be passed to the exception constructor, which should clone() it.