libDAI
Classes | Namespaces | Macros
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.

Classes

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

Namespaces

 dai
 Namespace for libDAI.
 

Macros

#define DAI_QUOTE(x)   #x
 Used by DAI_THROW. More...
 
#define DAI_TOSTRING(x)   DAI_QUOTE(x)
 Used by DAI_THROW. More...
 
#define FUNCTION_NAME   __func__
 Macro that simplifies throwing an exception with a useful default error message. More...
 
#define DAI_THROW(cod)   throw dai::Exception(dai::Exception::cod, __FILE__, FUNCTION_NAME, DAI_TOSTRING(__LINE__), "")
 
#define DAI_THROWE(cod, msg)   throw dai::Exception(dai::Exception::cod, __FILE__, FUNCTION_NAME, DAI_TOSTRING(__LINE__), msg)
 Macro that simplifies throwing an exception with a user-defined error message. More...
 
#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. More...
 
#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. More...
 

Detailed Description

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

Macro Definition Documentation

#define DAI_QUOTE (   x)    #x

Used by DAI_THROW.

#define DAI_TOSTRING (   x)    DAI_QUOTE(x)

Used by DAI_THROW.

#define FUNCTION_NAME   __func__

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
codCorresponds to one of the enum values of dai::Exception::Code
Example:
1 DAI_THROW(NOT_IMPLEMENTED);
#define DAI_THROWE (   cod,
  msg 
)    throw dai::Exception(dai::Exception::cod, __FILE__, FUNCTION_NAME, DAI_TOSTRING(__LINE__), msg)

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

Parameters
codCorresponds to one of the enum values of dai::Exception::Code
msgDetailed error message that will be written to std::cerr.
Example:
1 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 (   x)    do {DAI_ASSERT(x);} while(0)

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