diff options
author | Martin Braun <martin.braun@ettus.com> | 2017-08-22 18:11:41 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-09-01 07:58:45 -0700 |
commit | 1074a68dd7a0fa6d5ca23449446b90302ca755c9 (patch) | |
tree | 542bb024a4fbcce7255c4b0e9250745c5aeab7b0 /host/lib | |
parent | 6667aa071ecfac7418b49354b25c06a40ff4acfe (diff) | |
download | uhd-1074a68dd7a0fa6d5ca23449446b90302ca755c9.tar.gz uhd-1074a68dd7a0fa6d5ca23449446b90302ca755c9.tar.bz2 uhd-1074a68dd7a0fa6d5ca23449446b90302ca755c9.zip |
C API: Dboard EEPROM revision error handling fix
For invalid dboard revisions stored in the EEPROM, provide a better
error message.
Diffstat (limited to 'host/lib')
-rw-r--r-- | host/lib/usrp/dboard_eeprom_c.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/host/lib/usrp/dboard_eeprom_c.cpp b/host/lib/usrp/dboard_eeprom_c.cpp index 5d617f941..36a858d9c 100644 --- a/host/lib/usrp/dboard_eeprom_c.cpp +++ b/host/lib/usrp/dboard_eeprom_c.cpp @@ -17,6 +17,7 @@ #include <uhd/usrp/dboard_eeprom.h> #include <uhd/error.h> +#include <boost/format.hpp> #include <string.h> @@ -77,12 +78,33 @@ uhd_error uhd_dboard_eeprom_set_serial( ) } +//! Convert a string into an int. If that doesn't work, craft our own exception +// instead of using the Boost exception. We need to put this separate from the +// caller function because of macro expansion. +int _convert_rev_with_exception(const std::string &rev_str) +{ + try { + return std::stoi(rev_str); + } catch (const std::invalid_argument &) { + throw uhd::lookup_error(str( + boost::format("Error retrieving revision from string `%s`") + % rev_str + )); + } catch (const std::out_of_range &) { + throw uhd::lookup_error(str( + boost::format("Error retrieving revision from string `%s`") + % rev_str + )); + } +} + uhd_error uhd_dboard_eeprom_get_revision( uhd_dboard_eeprom_handle h, int* revision_out ){ UHD_SAFE_C_SAVE_ERROR(h, - *revision_out = std::stoi(h->dboard_eeprom_cpp.revision); + *revision_out = \ + _convert_rev_with_exception(h->dboard_eeprom_cpp.revision); ) } |