Commit f2b43796 authored by florent's avatar florent
Browse files

Make ExceptionAbstract derive from std::exception.

     * include/dynamic-graph/exception-abstract.h,
     * include/dynamic-graph/exception-factory.h,
     * include/dynamic-graph/exception-signal.h,
     * include/dynamic-graph/exception-traces.h,
     * include/dynamic-graph/signal-caster.h: This enables uses to catch
       a broader class of exceptions with messages using what() method.
parent 8b7d90ab
......@@ -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,
......
......@@ -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() {}
};
......
......@@ -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() {}
};
......
......@@ -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 () {}
};
......
......@@ -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); }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment