]> git.mxchange.org Git - simgear.git/commitdiff
cppbind: Tweak from_nasal error reporting
authorThomas Geymayer <tomgey@gmail.com>
Mon, 4 Mar 2013 22:15:00 +0000 (23:15 +0100)
committerThomas Geymayer <tomgey@gmail.com>
Mon, 4 Mar 2013 22:15:13 +0000 (23:15 +0100)
simgear/nasal/cppbind/detail/from_nasal_helper.cxx
simgear/nasal/cppbind/detail/from_nasal_helper.hxx

index cbac3558cd32da97c174c612efe24cc1fcf218ac..f6a173ea6e43fbad9bd10c3148b5d63e01b8451e 100644 (file)
 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));
index 00cca4b5a62317805dc73cfa1d58f76bb9443a0d..16e593bfa34acc201e994c6720e166d116f46b2c 100644 (file)
@@ -23,6 +23,7 @@
 #include "nasal_traits.hxx"
 
 #include <simgear/nasal/nasal.h>
+#include <simgear/structure/exception.hxx>
 
 #include <boost/utility/enable_if.hpp>
 #include <boost/type_traits.hpp>
@@ -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;
   };