USRP Hardware Driver and USRP Manual  Version: 3.13.0.HEAD-0-gf114cfa0
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 #ifndef INCLUDED_UHD_ERROR_H
9 #define INCLUDED_UHD_ERROR_H
10 
11 #include <stdlib.h>
12 
14 
21 typedef enum {
22 
27 
32 
37 
42 
59 
62 
65 
68 } uhd_error;
69 
70 #ifdef __cplusplus
71 #include <uhd/config.hpp>
72 #include <uhd/exception.hpp>
73 
74 #include <boost/exception/diagnostic_information.hpp>
75 
76 #include <string>
77 
78 UHD_API uhd_error error_from_uhd_exception(const uhd::exception* e);
79 
81 UHD_API std::string get_c_global_error_string();
82 
83 UHD_API void set_c_global_error_string(const std::string &msg);
84 
90 #define UHD_SAFE_C(...) \
91  try{ __VA_ARGS__ } \
92  catch (const uhd::exception &e) { \
93  set_c_global_error_string(e.what()); \
94  return error_from_uhd_exception(&e); \
95  } \
96  catch (const boost::exception &e) { \
97  set_c_global_error_string(boost::diagnostic_information(e)); \
98  return UHD_ERROR_BOOSTEXCEPT; \
99  } \
100  catch (const std::exception &e) { \
101  set_c_global_error_string(e.what()); \
102  return UHD_ERROR_STDEXCEPT; \
103  } \
104  catch (...) { \
105  set_c_global_error_string("Unrecognized exception caught."); \
106  return UHD_ERROR_UNKNOWN; \
107  } \
108  set_c_global_error_string("None"); \
109  return UHD_ERROR_NONE;
110 
116 #define UHD_SAFE_C_SAVE_ERROR(h, ...) \
117  h->last_error.clear(); \
118  try{ __VA_ARGS__ } \
119  catch (const uhd::exception &e) { \
120  set_c_global_error_string(e.what()); \
121  h->last_error = e.what(); \
122  return error_from_uhd_exception(&e); \
123  } \
124  catch (const boost::exception &e) { \
125  set_c_global_error_string(boost::diagnostic_information(e)); \
126  h->last_error = boost::diagnostic_information(e); \
127  return UHD_ERROR_BOOSTEXCEPT; \
128  } \
129  catch (const std::exception &e) { \
130  set_c_global_error_string(e.what()); \
131  h->last_error = e.what(); \
132  return UHD_ERROR_STDEXCEPT; \
133  } \
134  catch (...) { \
135  set_c_global_error_string("Unrecognized exception caught."); \
136  h->last_error = "Unrecognized exception caught."; \
137  return UHD_ERROR_UNKNOWN; \
138  } \
139  h->last_error = "None"; \
140  set_c_global_error_string("None"); \
141  return UHD_ERROR_NONE;
142 
143 extern "C" {
144 #endif
145 
147 
153  char* error_out,
154  size_t strbuffer_len
155 );
156 #ifdef __cplusplus
157 }
158 #endif
159 
160 #endif /* INCLUDED_UHD_ERROR_H */
Definition: exception.hpp:35
See uhd::runtime_error.
Definition: error.h:52
See uhd::io_error.
Definition: error.h:39
See uhd::system_error.
Definition: error.h:56
UHD_API uhd_error uhd_get_last_error(char *error_out, size_t strbuffer_len)
Return the last error string reported by UHD.
See uhd::not_implemented_error.
Definition: error.h:34
See uhd::exception.
Definition: error.h:58
See uhd::os_error.
Definition: error.h:41
See uhd::assertion_error.
Definition: error.h:44
Invalid device arguments.
Definition: error.h:26
See uhd::environment_error.
Definition: error.h:54
See uhd::key_error.
Definition: error.h:31
uhd_error
UHD error codes.
Definition: error.h:21
See uhd::usb_error.
Definition: error.h:36
See uhd::type_error.
Definition: error.h:48
See uhd::index_error.
Definition: error.h:29
No error thrown.
Definition: error.h:24
#define UHD_API
Definition: config.h:63
See uhd::value_error.
Definition: error.h:50
See uhd::lookup_error.
Definition: error.h:46
An unknown error was thrown.
Definition: error.h:67
A boost::exception was thrown.
Definition: error.h:61
A std::exception was thrown.
Definition: error.h:64