USRP Hardware Driver and USRP Manual  Version: 4.4.0.HEAD-0-g5fac246b
UHD and USRP Manual
error.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Ettus Research LLC
3  * Copyright 2018 Ettus Research, a National Instruments Company
4  *
5  * SPDX-License-Identifier: GPL-3.0-or-later
6  */
7 
8 #pragma once
9 
10 #include <stdlib.h>
11 
13 
20 typedef enum {
21 
26 
31 
36 
41 
58 
61 
64 
67 } uhd_error;
68 
69 #ifdef __cplusplus
70 #include <uhd/config.hpp>
71 #include <uhd/exception.hpp>
72 
73 #include <boost/exception/diagnostic_information.hpp>
74 
75 #include <string>
76 
77 UHD_API uhd_error error_from_uhd_exception(const uhd::exception* e);
78 
80 UHD_API std::string get_c_global_error_string();
81 
82 UHD_API void set_c_global_error_string(const std::string &msg);
83 
89 #define UHD_SAFE_C(...) \
90  try{ __VA_ARGS__ } \
91  catch (const uhd::exception &e) { \
92  set_c_global_error_string(e.what()); \
93  return error_from_uhd_exception(&e); \
94  } \
95  catch (const boost::exception &e) { \
96  set_c_global_error_string(boost::diagnostic_information(e)); \
97  return UHD_ERROR_BOOSTEXCEPT; \
98  } \
99  catch (const std::exception &e) { \
100  set_c_global_error_string(e.what()); \
101  return UHD_ERROR_STDEXCEPT; \
102  } \
103  catch (...) { \
104  set_c_global_error_string("Unrecognized exception caught."); \
105  return UHD_ERROR_UNKNOWN; \
106  } \
107  set_c_global_error_string("None"); \
108  return UHD_ERROR_NONE;
109 
115 #define UHD_SAFE_C_SAVE_ERROR(h, ...) \
116  h->last_error.clear(); \
117  try{ __VA_ARGS__ } \
118  catch (const uhd::exception &e) { \
119  set_c_global_error_string(e.what()); \
120  h->last_error = e.what(); \
121  return error_from_uhd_exception(&e); \
122  } \
123  catch (const boost::exception &e) { \
124  set_c_global_error_string(boost::diagnostic_information(e)); \
125  h->last_error = boost::diagnostic_information(e); \
126  return UHD_ERROR_BOOSTEXCEPT; \
127  } \
128  catch (const std::exception &e) { \
129  set_c_global_error_string(e.what()); \
130  h->last_error = e.what(); \
131  return UHD_ERROR_STDEXCEPT; \
132  } \
133  catch (...) { \
134  set_c_global_error_string("Unrecognized exception caught."); \
135  h->last_error = "Unrecognized exception caught."; \
136  return UHD_ERROR_UNKNOWN; \
137  } \
138  h->last_error = "None"; \
139  set_c_global_error_string("None"); \
140  return UHD_ERROR_NONE;
141 
142 extern "C" {
143 #endif
144 
146 
152  char* error_out,
153  size_t strbuffer_len
154 );
155 #ifdef __cplusplus
156 }
157 #endif
UHD_ERROR_SYSTEM
@ UHD_ERROR_SYSTEM
See uhd::system_error.
Definition: error.h:55
UHD_ERROR_ASSERTION
@ UHD_ERROR_ASSERTION
See uhd::assertion_error.
Definition: error.h:43
config.hpp
UHD_ERROR_EXCEPT
@ UHD_ERROR_EXCEPT
See uhd::exception.
Definition: error.h:57
UHD_ERROR_UNKNOWN
@ UHD_ERROR_UNKNOWN
An unknown error was thrown.
Definition: error.h:66
uhd::exception
Definition: exception.hpp:35
UHD_ERROR_RUNTIME
@ UHD_ERROR_RUNTIME
See uhd::runtime_error.
Definition: error.h:51
uhd_error
uhd_error
UHD error codes.
Definition: error.h:20
uhd_get_last_error
UHD_API uhd_error uhd_get_last_error(char *error_out, size_t strbuffer_len)
Return the last error string reported by UHD.
UHD_ERROR_OS
@ UHD_ERROR_OS
See uhd::os_error.
Definition: error.h:40
UHD_ERROR_LOOKUP
@ UHD_ERROR_LOOKUP
See uhd::lookup_error.
Definition: error.h:45
UHD_ERROR_ENVIRONMENT
@ UHD_ERROR_ENVIRONMENT
See uhd::environment_error.
Definition: error.h:53
UHD_ERROR_IO
@ UHD_ERROR_IO
See uhd::io_error.
Definition: error.h:38
UHD_ERROR_BOOSTEXCEPT
@ UHD_ERROR_BOOSTEXCEPT
A boost::exception was thrown.
Definition: error.h:60
UHD_API
#define UHD_API
Definition: config.h:87
UHD_ERROR_NONE
@ UHD_ERROR_NONE
No error thrown.
Definition: error.h:23
UHD_ERROR_VALUE
@ UHD_ERROR_VALUE
See uhd::value_error.
Definition: error.h:49
UHD_ERROR_KEY
@ UHD_ERROR_KEY
See uhd::key_error.
Definition: error.h:30
UHD_ERROR_USB
@ UHD_ERROR_USB
See uhd::usb_error.
Definition: error.h:35
UHD_ERROR_INDEX
@ UHD_ERROR_INDEX
See uhd::index_error.
Definition: error.h:28
UHD_ERROR_NOT_IMPLEMENTED
@ UHD_ERROR_NOT_IMPLEMENTED
See uhd::not_implemented_error.
Definition: error.h:33
UHD_ERROR_TYPE
@ UHD_ERROR_TYPE
See uhd::type_error.
Definition: error.h:47
exception.hpp
UHD_ERROR_STDEXCEPT
@ UHD_ERROR_STDEXCEPT
A std::exception was thrown.
Definition: error.h:63
UHD_ERROR_INVALID_DEVICE
@ UHD_ERROR_INVALID_DEVICE
Invalid device arguments.
Definition: error.h:25