assertions.h revision f59fb0e83fd0a4b41700d3f5eebdc8d21b173c2e
1// Copyright 2007-2010 Baptiste Lepilleur 2// Distributed under MIT license, or public domain if desired and 3// recognized in your jurisdiction. 4// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 5 6#ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED 7# define CPPTL_JSON_ASSERTIONS_H_INCLUDED 8 9#include <stdlib.h> 10 11#if !defined(JSON_IS_AMALGAMATION) 12# include <json/config.h> 13#endif // if !defined(JSON_IS_AMALGAMATION) 14 15#if JSON_USE_EXCEPTION 16#define JSON_ASSERT( condition ) assert( condition ); // @todo <= change this into an exception throw 17#define JSON_FAIL_MESSAGE( message ) throw std::runtime_error( message ); 18#else // JSON_USE_EXCEPTION 19#define JSON_ASSERT( condition ) assert( condition ); 20 21// The call to assert() will show the failure message in debug builds. In 22// release bugs we write to invalid memory in order to crash hard, so that a 23// debugger or crash reporter gets the chance to take over. We still call exit() 24// afterward in order to tell the compiler that this macro doesn't return. 25#define JSON_FAIL_MESSAGE( message ) { assert(false && message); strcpy(reinterpret_cast<char*>(666), message); exit(123); } 26 27#endif 28 29#define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) { JSON_FAIL_MESSAGE( message ) } 30 31#endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED 32