UHD 003.001.000
|
00001 // 00002 // Copyright 2010-2011 Ettus Research LLC 00003 // 00004 // This program is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 00018 #ifndef INCLUDED_UHD_UTILS_EXCEPTION_HPP 00019 #define INCLUDED_UHD_UTILS_EXCEPTION_HPP 00020 00021 #include <uhd/config.hpp> 00022 #include <boost/current_function.hpp> 00023 #include <stdexcept> 00024 #include <string> 00025 00036 namespace uhd{ 00037 00038 struct UHD_API exception : std::runtime_error{ 00039 exception(const std::string &what); 00040 virtual unsigned code(void) const = 0; 00041 }; 00042 00043 struct UHD_API assertion_error : exception{ 00044 assertion_error(const std::string &what); 00045 virtual unsigned code(void) const; 00046 }; 00047 00048 struct UHD_API lookup_error : exception{ 00049 lookup_error(const std::string &what); 00050 virtual unsigned code(void) const; 00051 }; 00052 00053 struct UHD_API index_error : lookup_error{ 00054 index_error(const std::string &what); 00055 virtual unsigned code(void) const; 00056 }; 00057 00058 struct UHD_API key_error : lookup_error{ 00059 key_error(const std::string &what); 00060 virtual unsigned code(void) const; 00061 }; 00062 00063 struct UHD_API type_error : exception{ 00064 type_error(const std::string &what); 00065 virtual unsigned code(void) const; 00066 }; 00067 00068 struct UHD_API value_error : exception{ 00069 value_error(const std::string &what); 00070 virtual unsigned code(void) const; 00071 }; 00072 00073 struct UHD_API runtime_error : exception{ 00074 runtime_error(const std::string &what); 00075 virtual unsigned code(void) const; 00076 }; 00077 00078 struct UHD_API not_implemented_error : runtime_error{ 00079 not_implemented_error(const std::string &what); 00080 virtual unsigned code(void) const; 00081 }; 00082 00083 struct UHD_API environment_error : exception{ 00084 environment_error(const std::string &what); 00085 virtual unsigned code(void) const; 00086 }; 00087 00088 struct UHD_API io_error : environment_error{ 00089 io_error(const std::string &what); 00090 virtual unsigned code(void) const; 00091 }; 00092 00093 struct UHD_API os_error : environment_error{ 00094 os_error(const std::string &what); 00095 virtual unsigned code(void) const; 00096 }; 00097 00098 struct UHD_API system_error : exception{ 00099 system_error(const std::string &what); 00100 virtual unsigned code(void) const; 00101 }; 00102 00109 #define UHD_THROW_SITE_INFO(what) std::string( \ 00110 std::string(what) + "\n" + \ 00111 " in " + std::string(BOOST_CURRENT_FUNCTION) + "\n" + \ 00112 " at " + std::string(__FILE__) + ":" + BOOST_STRINGIZE(__LINE__) + "\n" \ 00113 ) 00114 00119 #define UHD_THROW_INVALID_CODE_PATH() \ 00120 throw uhd::system_error(UHD_THROW_SITE_INFO("invalid code path")) 00121 00127 #define UHD_ASSERT_THROW(code) if (not (code)) \ 00128 throw uhd::assertion_error(UHD_THROW_SITE_INFO(#code)); \ 00129 else void(0) 00130 00131 } //namespace uhd 00132 00133 #endif /* INCLUDED_UHD_UTILS_EXCEPTION_HPP */