USRP Hardware Driver and USRP Manual  Version: 003.009.004-0-g2b5a88bb
UHD and USRP Manual
error.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Ettus Research LLC
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_UHD_ERROR_H
19 #define INCLUDED_UHD_ERROR_H
20 
21 #include <stdlib.h>
22 
24 
31 typedef enum {
32 
37 
42 
47 
52 
69 
72 
75 
78 } uhd_error;
79 
80 #ifdef __cplusplus
81 #include <uhd/config.hpp>
82 #include <uhd/exception.hpp>
83 
84 #include <boost/exception/diagnostic_information.hpp>
85 
86 #include <string>
87 
88 UHD_API uhd_error error_from_uhd_exception(const uhd::exception* e);
89 
90 UHD_API const std::string& get_c_global_error_string();
91 
92 UHD_API void set_c_global_error_string(const std::string &msg);
93 
99 #define UHD_SAFE_C(...) \
100  try{ __VA_ARGS__ } \
101  catch (const uhd::exception &e) { \
102  set_c_global_error_string(e.what()); \
103  return error_from_uhd_exception(&e); \
104  } \
105  catch (const boost::exception &e) { \
106  set_c_global_error_string(boost::diagnostic_information(e)); \
107  return UHD_ERROR_BOOSTEXCEPT; \
108  } \
109  catch (const std::exception &e) { \
110  set_c_global_error_string(e.what()); \
111  return UHD_ERROR_STDEXCEPT; \
112  } \
113  catch (...) { \
114  set_c_global_error_string("Unrecognized exception caught."); \
115  return UHD_ERROR_UNKNOWN; \
116  } \
117  set_c_global_error_string("None"); \
118  return UHD_ERROR_NONE;
119 
125 #define UHD_SAFE_C_SAVE_ERROR(h, ...) \
126  h->last_error.clear(); \
127  try{ __VA_ARGS__ } \
128  catch (const uhd::exception &e) { \
129  set_c_global_error_string(e.what()); \
130  h->last_error = e.what(); \
131  return error_from_uhd_exception(&e); \
132  } \
133  catch (const boost::exception &e) { \
134  set_c_global_error_string(boost::diagnostic_information(e)); \
135  h->last_error = boost::diagnostic_information(e); \
136  return UHD_ERROR_BOOSTEXCEPT; \
137  } \
138  catch (const std::exception &e) { \
139  set_c_global_error_string(e.what()); \
140  h->last_error = e.what(); \
141  return UHD_ERROR_STDEXCEPT; \
142  } \
143  catch (...) { \
144  set_c_global_error_string("Unrecognized exception caught."); \
145  h->last_error = "Unrecognized exception caught."; \
146  return UHD_ERROR_UNKNOWN; \
147  } \
148  h->last_error = "None"; \
149  set_c_global_error_string("None"); \
150  return UHD_ERROR_NONE;
151 
152 extern "C" {
153 #endif
154 
156 
162  char* error_out,
163  size_t strbuffer_len
164 );
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif /* INCLUDED_UHD_ERROR_H */
Definition: exception.hpp:45
See uhd::runtime_error.
Definition: error.h:62
See uhd::io_error.
Definition: error.h:49
See uhd::system_error.
Definition: error.h:66
See uhd::not_implemented_error.
Definition: error.h:44
uhd_error uhd_get_last_error(char *error_out, size_t strbuffer_len)
Return the last error string reported by UHD.
See uhd::exception.
Definition: error.h:68
See uhd::os_error.
Definition: error.h:51
See uhd::assertion_error.
Definition: error.h:54
Invalid device arguments.
Definition: error.h:36
See uhd::environment_error.
Definition: error.h:64
See uhd::key_error.
Definition: error.h:41
uhd_error
UHD error codes.
Definition: error.h:31
See uhd::usb_error.
Definition: error.h:46
See uhd::type_error.
Definition: error.h:58
See uhd::index_error.
Definition: error.h:39
No error thrown.
Definition: error.h:34
#define UHD_API
Definition: config.h:66
See uhd::value_error.
Definition: error.h:60
See uhd::lookup_error.
Definition: error.h:56
An unknown error was thrown.
Definition: error.h:77
A boost::exception was thrown.
Definition: error.h:71
A std::exception was thrown.
Definition: error.h:74