bugfix: Don't return a temporary string from exception::what

master
Marius Kintel 2015-02-10 18:59:11 -05:00
parent 4b4f4386bb
commit b6558889b4
4 changed files with 12 additions and 14 deletions

View File

@ -1,16 +1,14 @@
#include <exception>
class RecursionException: public std::exception {
class RecursionException: public std::runtime_error {
public:
RecursionException(const char *recursiontype, const std::string &name)
: rectype(recursiontype), name(name) {}
virtual ~RecursionException() throw() {}
virtual const char *what() const throw() {
static RecursionException create(const char *recursiontype, const std::string &name) {
std::stringstream out;
out << "ERROR: Recursion detected calling " << this->rectype << " '" << this->name << "'";
return out.str().c_str();
}
out << "ERROR: Recursion detected calling " << recursiontype << " '" << name << "'";
return RecursionException(out.str());
}
virtual ~RecursionException() throw() {}
private:
const char *rectype;
const std::string name;
RecursionException(const std::string &what_arg) : std::runtime_error(what_arg) {}
};

View File

@ -473,7 +473,7 @@ ExpressionFunctionCall::ExpressionFunctionCall(const std::string &funcname,
ValuePtr ExpressionFunctionCall::evaluate(const Context *context) const
{
if (StackCheck::inst()->check()) {
throw RecursionException("function", funcname);
throw RecursionException::create("function", funcname);
}
EvalContext c(context, this->call_arguments);

View File

@ -156,7 +156,7 @@ ValuePtr FunctionTailRecursion::evaluate(const Context *ctx, const EvalContext *
tmp.setVariables(definition_arguments, &ec);
c.apply_variables(tmp);
if (counter++ == 1000000) throw RecursionException("function", this->name);
if (counter++ == 1000000) throw RecursionException::create("function", this->name);
}
ValuePtr result = endexpr->evaluate(&c);

View File

@ -156,7 +156,7 @@ AbstractNode *ModuleInstantiation::evaluate(const Context *ctx) const
try {
AbstractNode *node = ctx->instantiate_module(*this, &c); // Passes c as evalctx
return node;
} catch (RecursionException &e) {
} catch (const RecursionException &e) {
PRINT(e.what());
return NULL;
}
@ -181,7 +181,7 @@ Module::~Module()
AbstractNode *Module::instantiate(const Context *ctx, const ModuleInstantiation *inst, EvalContext *evalctx) const
{
if (StackCheck::inst()->check()) {
throw RecursionException("module", inst->name());
throw RecursionException::create("module", inst->name());
return NULL;
}