summaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-02-24 14:07:11 -0800
committerJosh Blum <josh@joshknows.com>2011-02-24 14:07:11 -0800
commit4066b1f8fd87b1bca747d5b37a0b28179e188756 (patch)
treefda9e4d0c8d7232e891b9c46cf97384586daa153 /host/include
parentd588314b6f6205e0ea7051d8fc7836bdf9a6b16b (diff)
downloaduhd-4066b1f8fd87b1bca747d5b37a0b28179e188756.tar.gz
uhd-4066b1f8fd87b1bca747d5b37a0b28179e188756.tar.bz2
uhd-4066b1f8fd87b1bca747d5b37a0b28179e188756.zip
uhd: added a bunch of custom exceptions, not used yet
Diffstat (limited to 'host/include')
-rw-r--r--host/include/uhd/utils/assert.hpp9
-rw-r--r--host/include/uhd/utils/assert.ipp4
-rw-r--r--host/include/uhd/utils/exception.hpp106
3 files changed, 94 insertions, 25 deletions
diff --git a/host/include/uhd/utils/assert.hpp b/host/include/uhd/utils/assert.hpp
index 7f7b71cfb..cd752c1c1 100644
--- a/host/include/uhd/utils/assert.hpp
+++ b/host/include/uhd/utils/assert.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
@@ -25,13 +25,8 @@
namespace uhd{
- //! The exception to throw when assertions fail
- 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)) throw uhd::assert_error( \
+ #define UHD_ASSERT_THROW(_x) if (not (_x)) throw uhd::assertion_error( \
UHD_THROW_SITE_INFO("assertion failed: " + std::string(#_x)) \
); else void(0)
diff --git a/host/include/uhd/utils/assert.ipp b/host/include/uhd/utils/assert.ipp
index 6a8b3e417..4374fff67 100644
--- a/host/include/uhd/utils/assert.ipp
+++ b/host/include/uhd/utils/assert.ipp
@@ -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
@@ -37,7 +37,7 @@ namespace uhd{
if (i++ > 0) possible_values += ", ";
possible_values += boost::lexical_cast<std::string>(v);
}
- throw uhd::assert_error(str(boost::format(
+ throw uhd::assertion_error(str(boost::format(
"assertion failed:\n"
" %s is not a valid %s.\n"
" possible values are: [%s].\n"
diff --git a/host/include/uhd/utils/exception.hpp b/host/include/uhd/utils/exception.hpp
index e74c19b9c..71836e22e 100644
--- a/host/include/uhd/utils/exception.hpp
+++ b/host/include/uhd/utils/exception.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
@@ -24,22 +24,96 @@
#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 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.
*/
-#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" \
-)
+namespace uhd{
-/*!
- * 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 std::runtime_error(UHD_THROW_SITE_INFO("invalid code path"))
+ 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 */