Allow an extra developer message to wml_exception.
Also adds an extra macro VALIDATE_WITH_DEV_MESSAGE to add the message. This macro can be used instead of the normal VALIDATE macro.
This commit is contained in:
parent
acba693447
commit
3ca34572c1
2 changed files with 30 additions and 5 deletions
|
@ -28,14 +28,22 @@
|
|||
#include "gui/dialogs/message.hpp"
|
||||
#include "formula_string_utils.hpp"
|
||||
|
||||
|
||||
void wml_exception(const char* cond, const char* file,
|
||||
int line, const char *function, const std::string &message)
|
||||
void wml_exception(
|
||||
const char* cond
|
||||
, const char* file
|
||||
, int line
|
||||
, const char *function
|
||||
, const std::string& message
|
||||
, const std::string& dev_message)
|
||||
{
|
||||
std::ostringstream sstr;
|
||||
sstr << "Condition '" << cond << "' failed at "
|
||||
<< file << ":" << line << " in function '" << function << "'.";
|
||||
|
||||
if(!dev_message.empty()) {
|
||||
sstr << " Extra development information: " << dev_message;
|
||||
}
|
||||
|
||||
throw twml_exception(message, sstr.str());
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,18 @@ class display;
|
|||
} \
|
||||
} while(0)
|
||||
|
||||
#define VALIDATE_WITH_DEV_MESSAGE(cond, message, dev_message) \
|
||||
do { \
|
||||
if(!(cond)) { \
|
||||
wml_exception(#cond \
|
||||
, __FILE__ \
|
||||
, __LINE__ \
|
||||
, __func__ \
|
||||
, message \
|
||||
, dev_message); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* Helper function, don't call this directly.
|
||||
*
|
||||
|
@ -60,8 +72,13 @@ class display;
|
|||
* @param function The function in which the test failed.
|
||||
* @param message The translated message to show the user.
|
||||
*/
|
||||
void wml_exception(const char* cond, const char* file,
|
||||
int line, const char *function, const std::string &message);
|
||||
void wml_exception(
|
||||
const char* cond
|
||||
, const char* file
|
||||
, int line
|
||||
, const char *function
|
||||
, const std::string& message
|
||||
, const std::string& dev_message = "");
|
||||
|
||||
/** Helper class, don't construct this directly. */
|
||||
struct twml_exception
|
||||
|
|
Loading…
Add table
Reference in a new issue