diff --git a/include/dynamic-graph/exception-abstract.h b/include/dynamic-graph/exception-abstract.h index 548fb77bbe9b101d297e656ab5545cb8bdf28af5..b7e04ef9ad76f51086a2ca59cbf7e4b1cc939f38 100644 --- a/include/dynamic-graph/exception-abstract.h +++ b/include/dynamic-graph/exception-abstract.h @@ -43,7 +43,7 @@ namespace dynamicgraph { /* \class ExceptionAbstract */ -class DYNAMICGRAPH_EXPORT ExceptionAbstract +class DYNAMICGRAPH_EXPORT ExceptionAbstract : public std::exception { public: @@ -74,7 +74,7 @@ private: public: ExceptionAbstract( const int& code, const std::string & msg = "" ); - virtual ~ExceptionAbstract( void ){} + virtual ~ExceptionAbstract( void ) throw() {} /** Access to the error code. */ int getCode (void); @@ -87,6 +87,10 @@ public: */ const char *getMessage (void); + virtual const char* what() const throw() + { + return getStringMessage().c_str(); + } /** Print the error structure. */ DYNAMICGRAPH_EXPORT friend std::ostream & operator << (std::ostream & os, diff --git a/include/dynamic-graph/exception-factory.h b/include/dynamic-graph/exception-factory.h index 20176761144ffac4fae6eb4e9ae05a6966bb0109..c3c6fd9a010c54e61a61065130f987f9ae1611b1 100644 --- a/include/dynamic-graph/exception-factory.h +++ b/include/dynamic-graph/exception-factory.h @@ -64,7 +64,7 @@ public: const std::string & msg = "" ); ExceptionFactory ( const ExceptionFactory::ErrorCodeEnum& errcode, const std::string & msg,const char* format, ... ); - virtual ~ExceptionFactory( void ){} + virtual ~ExceptionFactory( void ) throw() {} }; diff --git a/include/dynamic-graph/exception-signal.h b/include/dynamic-graph/exception-signal.h index fb3d272c17594092385cba934deb7f287b031d0b..590034c9cba6f5d57a6918f66d2fb5234ec34a7b 100644 --- a/include/dynamic-graph/exception-signal.h +++ b/include/dynamic-graph/exception-signal.h @@ -63,7 +63,7 @@ public: const std::string & msg = "" ); ExceptionSignal( const ExceptionSignal::ErrorCodeEnum& errcode, const std::string & msg,const char* format, ... ); - virtual ~ExceptionSignal( void ){} + virtual ~ExceptionSignal( void ) throw() {} }; diff --git a/include/dynamic-graph/exception-traces.h b/include/dynamic-graph/exception-traces.h index 1eeecba1366cfc3ad46e3c720372dbefe9ebe4ed..a0db511f590c4bbafcd6e8afab6e6031069da053 100644 --- a/include/dynamic-graph/exception-traces.h +++ b/include/dynamic-graph/exception-traces.h @@ -58,7 +58,7 @@ public: const std::string & msg = "" ); ExceptionTraces( const ExceptionTraces::ErrorCodeEnum& errcode, const std::string & msg,const char* format, ... ); - virtual ~ExceptionTraces( void ){} + virtual ~ExceptionTraces( void ) throw () {} }; diff --git a/include/dynamic-graph/signal-caster.h b/include/dynamic-graph/signal-caster.h index 41f5a8a73c3e7c59c446e6abb9bab13103bfdbe1..6d9dee19e6bf09420616cdf78cc9a55eab10feb7 100644 --- a/include/dynamic-graph/signal-caster.h +++ b/include/dynamic-graph/signal-caster.h @@ -17,6 +17,7 @@ #include <iostream> #include <dynamic-graph/dynamic-graph-api.h> +#include "dynamic-graph/exception-signal.h" namespace dynamicgraph { @@ -101,7 +102,14 @@ template<typename T> void signal_disp(const T& value, std::ostream& os) { g_caster.disp(value, os); } template<typename T> T signal_cast(std::istringstream& iss) - { return boost::any_cast<T>(g_caster.cast(typeid(T), iss)); } + { + try { + return boost::any_cast<T>(g_caster.cast(typeid(T), iss)); + } catch (...) { + throw ExceptionSignal(ExceptionSignal::GENERIC, + "Exception boost::any_cast"); + } + } template<typename T> void signal_trace(const T& value, std::ostream& os) { g_caster.trace(value, os); }