diff options
| author | Martin Braun <martin.braun@ettus.com> | 2017-05-30 17:30:42 -0700 | 
|---|---|---|
| committer | Martin Braun <martin.braun@ettus.com> | 2017-12-22 15:03:58 -0800 | 
| commit | 7f0497ec5130d30ddb4e5242e0702041f420e488 (patch) | |
| tree | 10811aa11f92a64a74286dcde425b65fed6a5373 | |
| parent | 54acfcd1213a27cfa33b86751d2d3e9e186e1086 (diff) | |
| download | uhd-7f0497ec5130d30ddb4e5242e0702041f420e488.tar.gz uhd-7f0497ec5130d30ddb4e5242e0702041f420e488.tar.bz2 uhd-7f0497ec5130d30ddb4e5242e0702041f420e488.zip | |
rpc: Improved error handling
| -rw-r--r-- | host/lib/utils/rpc.hpp | 19 | 
1 files changed, 17 insertions, 2 deletions
| diff --git a/host/lib/utils/rpc.hpp b/host/lib/utils/rpc.hpp index 17e5fe099..dc6762928 100644 --- a/host/lib/utils/rpc.hpp +++ b/host/lib/utils/rpc.hpp @@ -19,6 +19,9 @@  #define INCLUDED_UTILS_RPC_HPP  #include <rpc/client.h> +#include <rpc/rpc_error.h> +#include <uhd/exception.hpp> +#include <boost/format.hpp>  namespace uhd { @@ -54,8 +57,20 @@ class rpc_client      return_type call(std::string const& func_name, Args&&... args)      {          std::lock_guard<std::mutex> lock(_mutex); -        return _client.call(func_name, std::forward<Args>(args)...) -            .template as<return_type>(); +        try { +            return _client.call(func_name, std::forward<Args>(args)...) +                .template as<return_type>(); +        } catch (const ::rpc::rpc_error &ex) { +            throw uhd::runtime_error(str( +                boost::format("Error during RPC call to `%s'. Error message: %s") +                % func_name % ex.what() +            )); +        } catch (const std::bad_cast& ex) { +            throw uhd::runtime_error(str( +                boost::format("Error during RPC call to `%s'. Error message: %s") +                % func_name % ex.what() +            )); +        }      };      /*! Perform an RPC call; also includes a token. | 
