From 7f0497ec5130d30ddb4e5242e0702041f420e488 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 30 May 2017 17:30:42 -0700 Subject: rpc: Improved error handling --- host/lib/utils/rpc.hpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'host/lib/utils') 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 +#include +#include +#include namespace uhd { @@ -54,8 +57,20 @@ class rpc_client return_type call(std::string const& func_name, Args&&... args) { std::lock_guard lock(_mutex); - return _client.call(func_name, std::forward(args)...) - .template as(); + try { + return _client.call(func_name, std::forward(args)...) + .template as(); + } 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. -- cgit v1.2.3