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")
{
}
}
- //----------------------------------------------------------------------------
- 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));
#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>
* 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:
/**
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;
};