summaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-05-05 17:03:59 -0700
committerJosh Blum <josh@joshknows.com>2010-05-05 17:03:59 -0700
commitf27400cd391d2d276df964d8c26ee08aa8ca3662 (patch)
tree084236f5fcdddf4aab1dc73ddf19bf02e716e0ea /host/include
parent3198ff91dcd3a06433654f9e50818f4566cbbe13 (diff)
downloaduhd-f27400cd391d2d276df964d8c26ee08aa8ca3662.tar.gz
uhd-f27400cd391d2d276df964d8c26ee08aa8ca3662.tar.bz2
uhd-f27400cd391d2d276df964d8c26ee08aa8ca3662.zip
Removed the boost exception stuff, replaced it with macro that formats the throw site information.
SWIG didnt handle the boost exception stuff, even with custom exception wrappers. Now the boost requirement can be lowered back to 3.6.
Diffstat (limited to 'host/include')
-rw-r--r--host/include/uhd/utils/CMakeLists.txt1
-rw-r--r--host/include/uhd/utils/assert.hpp21
-rw-r--r--host/include/uhd/utils/exception.hpp38
-rw-r--r--host/include/uhd/utils/props.hpp13
-rw-r--r--host/include/uhd/utils/safe_main.hpp3
5 files changed, 52 insertions, 24 deletions
diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt
index 2831ab0b0..f588c6310 100644
--- a/host/include/uhd/utils/CMakeLists.txt
+++ b/host/include/uhd/utils/CMakeLists.txt
@@ -18,6 +18,7 @@
INSTALL(FILES
algorithm.hpp
assert.hpp
+ exception.hpp
gain_handler.hpp
props.hpp
safe_main.hpp
diff --git a/host/include/uhd/utils/assert.hpp b/host/include/uhd/utils/assert.hpp
index ed0a95535..2f0ed4ff1 100644
--- a/host/include/uhd/utils/assert.hpp
+++ b/host/include/uhd/utils/assert.hpp
@@ -19,26 +19,24 @@
#define INCLUDED_UHD_UTILS_ASSERT_HPP
#include <uhd/config.hpp>
+#include <uhd/utils/exception.hpp>
#include <uhd/utils/algorithm.hpp>
#include <boost/format.hpp>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
-#include <boost/throw_exception.hpp>
-#include <boost/exception/info.hpp>
#include <stdexcept>
#include <string>
namespace uhd{
//! The exception to throw when assertions fail
- struct UHD_API assert_error : virtual std::exception, virtual boost::exception{};
-
- //! The assertion info, the code that failed
- typedef boost::error_info<struct tag_assert_info, std::string> assert_info;
+ struct UHD_API assert_error : std::runtime_error{
+ assert_error(const std::string &what);
+ };
//! Throw an assert error with throw-site information
#define UHD_ASSERT_THROW(_x) if (not (_x)) \
- BOOST_THROW_EXCEPTION(uhd::assert_error() << uhd::assert_info(#_x))
+ throw uhd::assert_error(UHD_THROW_SITE_INFO("assertion failed: " + std::string(#_x)))
/*!
* Check that an element is found in a container.
@@ -63,13 +61,14 @@ namespace uhd{
if (i++ > 0) possible_values += ", ";
possible_values += boost::lexical_cast<std::string>(v);
}
- boost::throw_exception(uhd::assert_error() << assert_info(str(boost::format(
- "Error: %s is not a valid %s. "
- "Possible values are: [%s]."
+ throw uhd::assert_error(str(boost::format(
+ "assertion failed:\n"
+ " %s is not a valid %s.\n"
+ " possible values are: [%s].\n"
)
% boost::lexical_cast<std::string>(value)
% what % possible_values
- )));
+ ));
}
}//namespace uhd
diff --git a/host/include/uhd/utils/exception.hpp b/host/include/uhd/utils/exception.hpp
new file mode 100644
index 000000000..40e81fae0
--- /dev/null
+++ b/host/include/uhd/utils/exception.hpp
@@ -0,0 +1,38 @@
+//
+// Copyright 2010 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 <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_UHD_UTILS_EXCEPTION_HPP
+#define INCLUDED_UHD_UTILS_EXCEPTION_HPP
+
+#include <uhd/config.hpp>
+#include <boost/current_function.hpp>
+#include <stdexcept>
+#include <string>
+
+/*!
+ * 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" \
+)
+
+#endif /* INCLUDED_UHD_UTILS_EXCEPTION_HPP */
diff --git a/host/include/uhd/utils/props.hpp b/host/include/uhd/utils/props.hpp
index 516102a5f..f376d2612 100644
--- a/host/include/uhd/utils/props.hpp
+++ b/host/include/uhd/utils/props.hpp
@@ -20,9 +20,8 @@
#include <uhd/config.hpp>
#include <uhd/wax.hpp>
+#include <uhd/utils/exception.hpp>
#include <boost/tuple/tuple.hpp>
-#include <boost/throw_exception.hpp>
-#include <boost/exception/info.hpp>
#include <stdexcept>
#include <vector>
#include <string>
@@ -59,25 +58,19 @@ namespace uhd{
const std::string &name = ""
);
- //! The exception to throw for property errors
- struct UHD_API prop_error : virtual std::exception, virtual boost::exception{};
-
- //! The property error info (verbose or message)
- typedef boost::error_info<struct tag_prop_info, std::string> prop_info;
-
/*!
* Throw when getting a not-implemented or write-only property.
* Throw-site information will be included with this error.
*/
#define UHD_THROW_PROP_GET_ERROR() \
- BOOST_THROW_EXCEPTION(uhd::prop_error() << uhd::prop_info("cannot get this property"))
+ throw std::runtime_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() \
- BOOST_THROW_EXCEPTION(uhd::prop_error() << uhd::prop_info("cannot set this property"))
+ throw std::runtime_error(UHD_THROW_SITE_INFO("cannot set this property"))
} //namespace uhd
diff --git a/host/include/uhd/utils/safe_main.hpp b/host/include/uhd/utils/safe_main.hpp
index a4e4e06e8..b682aa540 100644
--- a/host/include/uhd/utils/safe_main.hpp
+++ b/host/include/uhd/utils/safe_main.hpp
@@ -19,7 +19,6 @@
#define INCLUDED_UHD_UTILS_SAFE_MAIN_HPP
#include <uhd/config.hpp>
-#include <boost/exception/diagnostic_information.hpp>
#include <iostream>
#include <stdexcept>
@@ -34,8 +33,6 @@
int main(int argc, char *argv[]){ \
try { \
return _main(argc, argv); \
- } catch(const boost::exception &e){ \
- std::cerr << "Error: " << boost::diagnostic_information(e) << std::endl; \
} catch(const std::exception &e) { \
std::cerr << "Error: " << e.what() << std::endl; \
} catch(...) { \