From 555fb5c3a02f127f77e18add0ff16e5fab517bd2 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Sun, 26 Jul 2009 01:37:21 +0000 Subject: [PATCH] Fixed the Exception::what() function --- include/exceptions.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/include/exceptions.h b/include/exceptions.h index 38e296e..2df88b6 100644 --- a/include/exceptions.h +++ b/include/exceptions.h @@ -61,16 +61,19 @@ namespace YAML class Exception: public std::exception { public: Exception(int line_, int column_, const std::string& msg_) - : line(line_), column(column_), msg(msg_) {} + : line(line_), column(column_), msg(msg_) { + std::stringstream output; + output << "Error at line " << line+1 << ", column " << column+1 << ": " << msg; + what_ = output.str(); + } virtual ~Exception() throw() {} - virtual const char *what() const throw() { - std::stringstream output; - output << "Error at line " << line+1 << ", column " << column+1 << ": " << msg; - return output.str().c_str(); - } + virtual const char *what() const throw() { return what_.c_str(); } int line, column; std::string msg; + + private: + std::string what_; }; class ParserException: public Exception {