From 20a524d1a00497bdffda0292143d92e4d98cfbe9 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 24 Feb 2011 14:18:52 -0800 Subject: uhd: moved exception to top level include --- host/include/uhd/CMakeLists.txt | 1 + host/include/uhd/exception.hpp | 119 ++++++++++++++++++++++++++++++++++ host/include/uhd/utils/CMakeLists.txt | 3 +- host/include/uhd/utils/assert.hpp | 3 +- host/include/uhd/utils/exception.hpp | 119 ---------------------------------- host/include/uhd/utils/props.hpp | 9 ++- 6 files changed, 126 insertions(+), 128 deletions(-) create mode 100644 host/include/uhd/exception.hpp delete mode 100644 host/include/uhd/utils/exception.hpp (limited to 'host/include') diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt index b7a22cf0b..db755511e 100644 --- a/host/include/uhd/CMakeLists.txt +++ b/host/include/uhd/CMakeLists.txt @@ -25,6 +25,7 @@ INSTALL(FILES config.hpp convert.hpp device.hpp + exception.hpp version.hpp wax.hpp DESTINATION ${INCLUDE_DIR}/uhd diff --git a/host/include/uhd/exception.hpp b/host/include/uhd/exception.hpp new file mode 100644 index 000000000..71836e22e --- /dev/null +++ b/host/include/uhd/exception.hpp @@ -0,0 +1,119 @@ +// +// Copyright 2010-2011 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#ifndef INCLUDED_UHD_UTILS_EXCEPTION_HPP +#define INCLUDED_UHD_UTILS_EXCEPTION_HPP + +#include +#include +#include +#include + +/*! + * Define common exceptions used throughout the code: + * + * - The python built-in exceptions were used as inspiration. + * - Exceptions inherit from std::exception to provide what(). + * - Exceptions inherit from uhd::exception to provide code(). + * + * The code() provides an error code which allows the application + * the option of printing a cryptic error message from the 1990s. + */ +namespace uhd{ + + struct UHD_API exception : std::runtime_error{ + exception(const std::string &what); + virtual unsigned code(void) const = 0; + }; + + struct UHD_API assertion_error : exception{ + assertion_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API lookup_error : exception{ + lookup_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API index_error : lookup_error{ + index_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API key_error : lookup_error{ + key_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API value_error : exception{ + value_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API runtime_error : exception{ + runtime_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API not_implemented_error : runtime_error{ + not_implemented_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API environment_error : exception{ + environment_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API io_error : environment_error{ + io_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API os_error : environment_error{ + os_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API system_error : exception{ + system_error(const std::string &what); + virtual unsigned code(void) const; + }; + + /*! + * Create a formated string with throw-site information. + * Fills in the function name, file name, and line number. + * \param what the std::exeption message + * \return the formatted exception message + */ + #define UHD_THROW_SITE_INFO(what) std::string( \ + std::string(what) + "\n" + \ + " in " + std::string(BOOST_CURRENT_FUNCTION) + "\n" + \ + " at " + std::string(__FILE__) + ":" + BOOST_STRINGIZE(__LINE__) + "\n" \ + ) + + /*! + * Throws an invalid code path exception with throw-site information. + * Use this macro in places that code execution is not supposed to go. + */ + #define UHD_THROW_INVALID_CODE_PATH() \ + throw uhd::system_error(UHD_THROW_SITE_INFO("invalid code path")) + +} //namespace uhd + +#endif /* INCLUDED_UHD_UTILS_EXCEPTION_HPP */ diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt index b39b6083c..b638431d3 100644 --- a/host/include/uhd/utils/CMakeLists.txt +++ b/host/include/uhd/utils/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,7 +21,6 @@ INSTALL(FILES assert.ipp byteswap.hpp byteswap.ipp - exception.hpp gain_group.hpp images.hpp pimpl.hpp diff --git a/host/include/uhd/utils/assert.hpp b/host/include/uhd/utils/assert.hpp index cd752c1c1..1be4237d6 100644 --- a/host/include/uhd/utils/assert.hpp +++ b/host/include/uhd/utils/assert.hpp @@ -19,8 +19,7 @@ #define INCLUDED_UHD_UTILS_ASSERT_HPP #include -#include -#include +#include #include namespace uhd{ diff --git a/host/include/uhd/utils/exception.hpp b/host/include/uhd/utils/exception.hpp deleted file mode 100644 index 71836e22e..000000000 --- a/host/include/uhd/utils/exception.hpp +++ /dev/null @@ -1,119 +0,0 @@ -// -// Copyright 2010-2011 Ettus Research LLC -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#ifndef INCLUDED_UHD_UTILS_EXCEPTION_HPP -#define INCLUDED_UHD_UTILS_EXCEPTION_HPP - -#include -#include -#include -#include - -/*! - * Define common exceptions used throughout the code: - * - * - The python built-in exceptions were used as inspiration. - * - Exceptions inherit from std::exception to provide what(). - * - Exceptions inherit from uhd::exception to provide code(). - * - * The code() provides an error code which allows the application - * the option of printing a cryptic error message from the 1990s. - */ -namespace uhd{ - - struct UHD_API exception : std::runtime_error{ - exception(const std::string &what); - virtual unsigned code(void) const = 0; - }; - - struct UHD_API assertion_error : exception{ - assertion_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API lookup_error : exception{ - lookup_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API index_error : lookup_error{ - index_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API key_error : lookup_error{ - key_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API value_error : exception{ - value_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API runtime_error : exception{ - runtime_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API not_implemented_error : runtime_error{ - not_implemented_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API environment_error : exception{ - environment_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API io_error : environment_error{ - io_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API os_error : environment_error{ - os_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API system_error : exception{ - system_error(const std::string &what); - virtual unsigned code(void) const; - }; - - /*! - * Create a formated string with throw-site information. - * Fills in the function name, file name, and line number. - * \param what the std::exeption message - * \return the formatted exception message - */ - #define UHD_THROW_SITE_INFO(what) std::string( \ - std::string(what) + "\n" + \ - " in " + std::string(BOOST_CURRENT_FUNCTION) + "\n" + \ - " at " + std::string(__FILE__) + ":" + BOOST_STRINGIZE(__LINE__) + "\n" \ - ) - - /*! - * Throws an invalid code path exception with throw-site information. - * Use this macro in places that code execution is not supposed to go. - */ - #define UHD_THROW_INVALID_CODE_PATH() \ - throw uhd::system_error(UHD_THROW_SITE_INFO("invalid code path")) - -} //namespace uhd - -#endif /* INCLUDED_UHD_UTILS_EXCEPTION_HPP */ diff --git a/host/include/uhd/utils/props.hpp b/host/include/uhd/utils/props.hpp index fbca03019..81737423a 100644 --- a/host/include/uhd/utils/props.hpp +++ b/host/include/uhd/utils/props.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -20,8 +20,7 @@ #include #include -#include -#include +#include #include #include @@ -68,14 +67,14 @@ namespace uhd{ * Throw-site information will be included with this error. */ #define UHD_THROW_PROP_GET_ERROR() \ - throw std::runtime_error(UHD_THROW_SITE_INFO("cannot get this property")) + throw uhd::key_error(UHD_THROW_SITE_INFO("cannot get this property")) /*! * Throw when setting a not-implemented or read-only property. * Throw-site information will be included with this error. */ #define UHD_THROW_PROP_SET_ERROR() \ - throw std::runtime_error(UHD_THROW_SITE_INFO("cannot set this property")) + throw uhd::key_error(UHD_THROW_SITE_INFO("cannot set this property")) } //namespace uhd -- cgit v1.2.3