From 24b418598ad2637f1f929380047f85d2cf2b7b33 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 18 Jun 2012 18:28:19 +0000 Subject: [PATCH] Make EnumWriter exceptions a bit more informative. git-svn-id: svn://localhost/ardour2/branches/3.0@12758 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/pbd/enumwriter.cc | 8 ++++---- libs/pbd/pbd/enumwriter.h | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/libs/pbd/enumwriter.cc b/libs/pbd/enumwriter.cc index 3ce296c664..6d911b2dea 100644 --- a/libs/pbd/enumwriter.cc +++ b/libs/pbd/enumwriter.cc @@ -127,7 +127,7 @@ EnumWriter::write (string type, int value) if (x == registry.end()) { error << string_compose (_("EnumWriter: unknown enumeration type \"%1\""), type) << endmsg; - throw unknown_enumeration(); + throw unknown_enumeration (type); } if (x->second.bitwise) { @@ -144,7 +144,7 @@ EnumWriter::read (string type, string value) if (x == registry.end()) { error << string_compose (_("EnumWriter: unknown enumeration type \"%1\""), type) << endmsg; - throw unknown_enumeration(); + throw unknown_enumeration (type); } if (x->second.bitwise) { @@ -267,7 +267,7 @@ EnumWriter::read_bits (EnumRegistration& er, string str) } while (true); if (!found) { - throw unknown_enumeration(); + throw unknown_enumeration (str); } return result; @@ -316,7 +316,7 @@ EnumWriter::read_distinct (EnumRegistration& er, string str) } } - throw unknown_enumeration(); + throw unknown_enumeration(str); } void diff --git a/libs/pbd/pbd/enumwriter.h b/libs/pbd/pbd/enumwriter.h index 600f59bf29..95f1ea9e9f 100644 --- a/libs/pbd/pbd/enumwriter.h +++ b/libs/pbd/pbd/enumwriter.h @@ -25,13 +25,26 @@ #include #include #include - +#include namespace PBD { class unknown_enumeration : public std::exception { public: - virtual const char *what() const throw() { return "unknown enumerator in PBD::EnumWriter"; } + unknown_enumeration (std::string const & e) throw() { + std::stringstream s; + s << "unknown enumerator " << e << " in PBD::EnumWriter"; + _message = s.str (); + } + + ~unknown_enumeration () throw() {} + + virtual const char *what() const throw() { + return _message.c_str(); + } + +private: + std::string _message; }; class EnumWriter {