Added FAIL and FAIL_WITH_DEV_MESSAGE macros.

These macros allow to throw an wml_exception without any condition. This
can be used when a code path is reached that should be unreachable with
valid WML.
This commit is contained in:
Mark de Wever 2012-05-19 19:35:44 +00:00
parent 050cff18a7
commit cd5bc7f11a
3 changed files with 23 additions and 2 deletions

View file

@ -285,6 +285,7 @@ Version 1.11.0-svn:
* Fixed: grids now recursively search for widgets by pointer.
* Fixed: Wrong current side number after side turns (bug #19735)
It also affected the lua field wesnoth.current.side
* Added: Fail macros FAIL and FAIL_WITH_DEV_MESSAGE.
Version 1.10.0:
* Campaigns:

View file

@ -41,8 +41,13 @@ void wml_exception(
, const std::string& dev_message)
{
std::ostringstream sstr;
sstr << "Condition '" << cond << "' failed at "
<< file << ":" << line << " in function '" << function << "'.";
if(cond) {
sstr << "Condition '" << cond << "' failed at ";
} else {
sstr << "Unconditional failure at ";
}
sstr << file << ":" << line << " in function '" << function << "'.";
if(!dev_message.empty()) {
sstr << " Extra development information: " << dev_message;

View file

@ -66,6 +66,21 @@ class display;
} \
} while(0)
#define FAIL(message) \
do { \
wml_exception(NULL, __FILE__, __LINE__, __func__, message); \
} while(0)
#define FAIL_WITH_DEV_MESSAGE(message, dev_message) \
do { \
wml_exception(NULL \
, __FILE__ \
, __LINE__ \
, __func__ \
, message \
, dev_message); \
} while(0)
/**
* Helper function, don't call this directly.
*