USRP Hardware Driver and USRP Manual  Version: 3.15.0.HEAD-0-gaea0e2de
UHD and USRP Manual
safe_main.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2010 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_UTILS_SAFE_MAIN_HPP
9 #define INCLUDED_UHD_UTILS_SAFE_MAIN_HPP
10 
11 #include <uhd/config.hpp>
12 #include <iostream>
13 #include <stdexcept>
14 
22 #define UHD_SAFE_MAIN(_argc, _argv) \
23  _main(int, char* []); \
24  int main(int argc, char* argv[]) \
25  { \
26  try { \
27  return _main(argc, argv); \
28  } catch (const std::exception& e) { \
29  std::cerr << "Error: " << e.what() << std::endl; \
30  } catch (...) { \
31  std::cerr << "Error: unknown exception" << std::endl; \
32  } \
33  return ~0; \
34  } \
35  int _main(_argc, _argv)
36 
37 #endif /* INCLUDED_UHD_UTILS_SAFE_MAIN_HPP */