include/dai/exceptions.h File Reference

Defines the Exception class and macros for throwing exceptions and doing assertions. More...

#include <exception>
#include <stdexcept>
#include <string>
#include <iostream>

Go to the source code of this file.

Namespaces

namespace  dai

Classes

class  dai::Exception
 Error handling in libDAI is done by throwing an instance of the Exception class. More...

Defines

#define DAI_QUOTE(x)   #x
 Used by DAI_THROW.
#define DAI_TOSTRING(x)   DAI_QUOTE(x)
 Used by DAI_THROW.
#define DAI_THROW(cod)   throw dai::Exception(dai::Exception::cod, std::string(__FILE__ ", line " DAI_TOSTRING(__LINE__)))
 Macro that simplifies throwing an exception with a useful default error message.
#define DAI_THROWE(cod, msg)   throw dai::Exception(dai::Exception::cod, std::string(__FILE__ ", line " DAI_TOSTRING(__LINE__)), msg)
 Macro that simplifies throwing an exception with a user-defined error message.
#define DAI_ASSERT(condition)   ((condition) ? ((void)0) : DAI_THROWE(ASSERTION_FAILED, std::string("Assertion \"" #condition "\" failed")))
 Assertion mechanism, similar to the standard assert() macro. It is always active, even if NDEBUG is defined.
#define DAI_DEBASSERT(x)   do {DAI_ASSERT(x);} while(0)
 Assertion mechanism similar to DAI_ASSERT which is only active if DAI_DEBUG is defined.


Detailed Description

Defines the Exception class and macros for throwing exceptions and doing assertions.


Define Documentation

#define DAI_QUOTE (  )     #x

Used by DAI_THROW.

#define DAI_TOSTRING (  )     DAI_QUOTE(x)

Used by DAI_THROW.

#define DAI_THROW ( cod   )     throw dai::Exception(dai::Exception::cod, std::string(__FILE__ ", line " DAI_TOSTRING(__LINE__)))

Macro that simplifies throwing an exception with a useful default error message.

The error message consists of a description of the exception, the source code file and line number where the exception has been thrown.

Parameters:
cod Corresponds to one of the enum values of dai::Exception::Code
Example:
  DAI_THROW(NOT_IMPLEMENTED);

#define DAI_THROWE ( cod,
msg   )     throw dai::Exception(dai::Exception::cod, std::string(__FILE__ ", line " DAI_TOSTRING(__LINE__)), msg)

Macro that simplifies throwing an exception with a user-defined error message.

Parameters:
cod Corresponds to one of the enum values of dai::Exception::Code
msg Detailed error message that will be written to std::cerr.
Example:
  DAI_THROWE(NOT_IMPLEMENTED,"Detailed error message");
Examples:
uai2010-aie-solver.cpp.

#define DAI_ASSERT ( condition   )     ((condition) ? ((void)0) : DAI_THROWE(ASSERTION_FAILED, std::string("Assertion \"" #condition "\" failed")))

Assertion mechanism, similar to the standard assert() macro. It is always active, even if NDEBUG is defined.

Examples:
example_bipgraph.cpp, example_permute.cpp, and example_varset.cpp.

#define DAI_DEBASSERT (  )     do {DAI_ASSERT(x);} while(0)

Assertion mechanism similar to DAI_ASSERT which is only active if DAI_DEBUG is defined.


Generated on Thu Aug 5 19:04:01 2010 for libDAI by  doxygen 1.5.5