UHD  003.003.002
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
include/uhd/exception.hpp
Go to the documentation of this file.
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_EXCEPTION_HPP
00019 #define INCLUDED_UHD_EXCEPTION_HPP
00020 
00021 #include <uhd/config.hpp>
00022 #include <boost/current_function.hpp>
00023 #include <stdexcept>
00024 #include <string>
00025 
00043 namespace uhd{
00044 
00045     struct UHD_API exception : std::runtime_error{
00046         exception(const std::string &what);
00047         virtual unsigned code(void) const = 0;
00048         virtual exception *dynamic_clone(void) const = 0;
00049         virtual void dynamic_throw(void) const = 0;
00050     };
00051 
00052     struct UHD_API assertion_error : exception{
00053         assertion_error(const std::string &what);
00054         virtual unsigned code(void) const;
00055         virtual assertion_error *dynamic_clone(void) const;
00056         virtual void dynamic_throw(void) const;
00057     };
00058 
00059     struct UHD_API lookup_error : exception{
00060         lookup_error(const std::string &what);
00061         virtual unsigned code(void) const;
00062         virtual lookup_error *dynamic_clone(void) const;
00063         virtual void dynamic_throw(void) const;
00064     };
00065 
00066     struct UHD_API index_error : lookup_error{
00067         index_error(const std::string &what);
00068         virtual unsigned code(void) const;
00069         virtual index_error *dynamic_clone(void) const;
00070         virtual void dynamic_throw(void) const;
00071     };
00072 
00073     struct UHD_API key_error : lookup_error{
00074         key_error(const std::string &what);
00075         virtual unsigned code(void) const;
00076         virtual key_error *dynamic_clone(void) const;
00077         virtual void dynamic_throw(void) const;
00078     };
00079 
00080     struct UHD_API type_error : exception{
00081         type_error(const std::string &what);
00082         virtual unsigned code(void) const;
00083         virtual type_error *dynamic_clone(void) const;
00084         virtual void dynamic_throw(void) const;
00085     };
00086 
00087     struct UHD_API value_error : exception{
00088         value_error(const std::string &what);
00089         virtual unsigned code(void) const;
00090         virtual value_error *dynamic_clone(void) const;
00091         virtual void dynamic_throw(void) const;
00092     };
00093 
00094     struct UHD_API runtime_error : exception{
00095         runtime_error(const std::string &what);
00096         virtual unsigned code(void) const;
00097         virtual runtime_error *dynamic_clone(void) const;
00098         virtual void dynamic_throw(void) const;
00099     };
00100 
00101     struct UHD_API not_implemented_error : runtime_error{
00102         not_implemented_error(const std::string &what);
00103         virtual unsigned code(void) const;
00104         virtual not_implemented_error *dynamic_clone(void) const;
00105         virtual void dynamic_throw(void) const;
00106     };
00107 
00108     struct UHD_API environment_error : exception{
00109         environment_error(const std::string &what);
00110         virtual unsigned code(void) const;
00111         virtual environment_error *dynamic_clone(void) const;
00112         virtual void dynamic_throw(void) const;
00113     };
00114 
00115     struct UHD_API io_error : environment_error{
00116         io_error(const std::string &what);
00117         virtual unsigned code(void) const;
00118         virtual io_error *dynamic_clone(void) const;
00119         virtual void dynamic_throw(void) const;
00120     };
00121 
00122     struct UHD_API os_error : environment_error{
00123         os_error(const std::string &what);
00124         virtual unsigned code(void) const;
00125         virtual os_error *dynamic_clone(void) const;
00126         virtual void dynamic_throw(void) const;
00127     };
00128 
00129     struct UHD_API system_error : exception{
00130         system_error(const std::string &what);
00131         virtual unsigned code(void) const;
00132         virtual system_error *dynamic_clone(void) const;
00133         virtual void dynamic_throw(void) const;
00134     };
00135 
00142     #define UHD_THROW_SITE_INFO(what) std::string( \
00143         std::string(what) + "\n" + \
00144         "  in " + std::string(BOOST_CURRENT_FUNCTION) + "\n" + \
00145         "  at " + std::string(__FILE__) + ":" + BOOST_STRINGIZE(__LINE__) + "\n" \
00146     )
00147 
00152     #define UHD_THROW_INVALID_CODE_PATH() \
00153         throw uhd::system_error(UHD_THROW_SITE_INFO("invalid code path"))
00154 
00160     #define UHD_ASSERT_THROW(code) if (not (code)) \
00161         throw uhd::assertion_error(UHD_THROW_SITE_INFO(#code)); \
00162     else void(0)
00163 
00164 } //namespace uhd
00165 
00166 #endif /* INCLUDED_UHD_EXCEPTION_HPP */