diff options
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/exception.hpp | 5 | ||||
-rw-r--r-- | host/include/uhd/types/dict.ipp | 6 | ||||
-rw-r--r-- | host/include/uhd/wax.hpp | 18 |
3 files changed, 18 insertions, 11 deletions
diff --git a/host/include/uhd/exception.hpp b/host/include/uhd/exception.hpp index 9acc768ed..e2a50bf1e 100644 --- a/host/include/uhd/exception.hpp +++ b/host/include/uhd/exception.hpp @@ -60,6 +60,11 @@ namespace uhd{ virtual unsigned code(void) const; }; + struct UHD_API type_error : exception{ + type_error(const std::string &what); + virtual unsigned code(void) const; + }; + struct UHD_API value_error : exception{ value_error(const std::string &what); virtual unsigned code(void) const; diff --git a/host/include/uhd/types/dict.ipp b/host/include/uhd/types/dict.ipp index 0c014474e..5e9cf97ad 100644 --- a/host/include/uhd/types/dict.ipp +++ b/host/include/uhd/types/dict.ipp @@ -18,18 +18,18 @@ #ifndef INCLUDED_UHD_TYPES_DICT_IPP #define INCLUDED_UHD_TYPES_DICT_IPP +#include <uhd/exception.hpp> #include <boost/foreach.hpp> #include <boost/format.hpp> #include <boost/lexical_cast.hpp> -#include <stdexcept> #include <typeinfo> namespace uhd{ namespace /*anon*/{ template<typename Key, typename Val> - struct key_not_found: std::out_of_range{ - key_not_found(const Key &key): std::out_of_range( + struct key_not_found: uhd::key_error{ + key_not_found(const Key &key): uhd::key_error( str(boost::format( "key \"%s\" not found in dict(%s, %s)" ) % boost::lexical_cast<std::string>(key) diff --git a/host/include/uhd/wax.hpp b/host/include/uhd/wax.hpp index 14e6734a5..6fd2b8652 100644 --- a/host/include/uhd/wax.hpp +++ b/host/include/uhd/wax.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -19,7 +19,10 @@ #define INCLUDED_WAX_HPP #include <uhd/config.hpp> +#include <uhd/exception.hpp> #include <boost/any.hpp> +#include <typeinfo> +#include <string> /*! * WAX - it's a metaphor! @@ -47,12 +50,6 @@ namespace wax{ /*! - * The wax::bad cast will be thrown when - * cast is called with the wrong typeid. - */ - typedef boost::bad_any_cast bad_cast; - - /*! * WAX object base class: * * A wax obj has two major purposes: @@ -140,7 +137,12 @@ namespace wax{ * \throw wax::bad_cast when the cast fails */ template<class T> T as(void) const{ - return boost::any_cast<T>(resolve()); + try{ + return boost::any_cast<T>(resolve()); + } + catch(const boost::bad_any_cast &e){ + throw uhd::type_error(std::string("") + "Cannot wax cast " + type().name() + " to " + typeid(T).name() + " " + e.what()); + } } private: |