From 11f98f1cc6a1c19c9de966cd777533ca53b61835 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Fri, 10 Jul 2009 04:17:30 +0000 Subject: [PATCH] (Finally) overrode Exception::what()\n --- include/exceptions.h | 6 ++++++ util/parse.cpp | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/exceptions.h b/include/exceptions.h index 784dc05..38e296e 100644 --- a/include/exceptions.h +++ b/include/exceptions.h @@ -2,6 +2,7 @@ #include #include +#include namespace YAML { @@ -62,6 +63,11 @@ namespace YAML Exception(int line_, int column_, const std::string& msg_) : line(line_), column(column_), msg(msg_) {} 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(); + } int line, column; std::string msg; diff --git a/util/parse.cpp b/util/parse.cpp index 1632041..12f4e6c 100644 --- a/util/parse.cpp +++ b/util/parse.cpp @@ -15,7 +15,7 @@ int main(int argc, char **argv) YAML::Node doc; parser.GetNextDocument(doc); } catch(const YAML::Exception& e) { - std::cerr << "Error at line " << e.line << ", col " << e.column << ": " << e.msg << "\n"; + std::cerr << e.what() << "\n"; } return 0; }