From 2db885907670c5ba020f9daadf2c869c7ac924e5 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Mon, 4 Mar 2013 23:15:00 +0100 Subject: [PATCH] cppbind: Tweak from_nasal error reporting --- .../nasal/cppbind/detail/from_nasal_helper.cxx | 16 +++++++--------- .../nasal/cppbind/detail/from_nasal_helper.hxx | 9 +++------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/simgear/nasal/cppbind/detail/from_nasal_helper.cxx b/simgear/nasal/cppbind/detail/from_nasal_helper.cxx index cbac3558..f6a173ea 100644 --- a/simgear/nasal/cppbind/detail/from_nasal_helper.cxx +++ b/simgear/nasal/cppbind/detail/from_nasal_helper.cxx @@ -25,14 +25,15 @@ namespace nasal { //---------------------------------------------------------------------------- - bad_nasal_cast::bad_nasal_cast() + bad_nasal_cast::bad_nasal_cast(): + sg_exception("conversion failed", "bad_nasal_cast") { } //---------------------------------------------------------------------------- bad_nasal_cast::bad_nasal_cast(const std::string& msg): - _msg( msg ) + sg_exception(msg, "bad_nasal_cast") { } @@ -43,17 +44,14 @@ namespace nasal } - //---------------------------------------------------------------------------- - const char* bad_nasal_cast::what() const throw() - { - return _msg.empty() ? bad_cast::what() : _msg.c_str(); - } - //---------------------------------------------------------------------------- std::string from_nasal_helper(naContext c, naRef ref, const std::string*) { naRef na_str = naStringValue(c, ref); - if( !naIsString(na_str) ) + + if( naIsNil(na_str) ) + return std::string(); + else if( !naIsString(na_str) ) throw bad_nasal_cast("Not convertible to string"); return std::string(naStr_data(na_str), naStr_len(na_str)); diff --git a/simgear/nasal/cppbind/detail/from_nasal_helper.hxx b/simgear/nasal/cppbind/detail/from_nasal_helper.hxx index 00cca4b5..16e593bf 100644 --- a/simgear/nasal/cppbind/detail/from_nasal_helper.hxx +++ b/simgear/nasal/cppbind/detail/from_nasal_helper.hxx @@ -23,6 +23,7 @@ #include "nasal_traits.hxx" #include +#include #include #include @@ -42,7 +43,8 @@ namespace nasal * Thrown when converting a type from/to Nasal has failed */ class bad_nasal_cast: - public std::bad_cast + public std::bad_cast, + public sg_exception { public: /** @@ -59,11 +61,6 @@ namespace nasal virtual ~bad_nasal_cast() throw(); - /** - * Get a description of the cause of the failed cast. - */ - virtual const char* what() const throw(); - protected: std::string _msg; }; -- 2.39.5