Statistics
| Branch: | Tag: | Revision:

root / host / lib / exception.cpp @ db5eb382

History | View | Annotate | Download (2.22 KB)

1
//
2
// Copyright 2011 Ettus Research LLC
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
//
17

    
18
#include <uhd/exception.hpp>
19
#include <boost/functional/hash.hpp>
20
#include <boost/format.hpp>
21

    
22
using namespace uhd;
23

    
24
exception::exception(const std::string &what):
25
    std::runtime_error(what){/* NOP */}
26

    
27
#define make_exception_impl(name, class, base) \
28
    class::class(const std::string &what): \
29
        base(str(boost::format("%s: %s") % name % what)){} \
30
    unsigned class::code(void) const{return boost::hash<std::string>()(#class) & 0xfff;} \
31
    class *class::dynamic_clone(void) const{return new class(*this);} \
32
    void class::dynamic_throw(void) const{throw *this;}
33

    
34
make_exception_impl("AssertionError",        assertion_error,         exception)
35
make_exception_impl("LookupError",           lookup_error,            exception)
36
make_exception_impl("IndexError",            index_error,             lookup_error)
37
make_exception_impl("KeyError",              key_error,               lookup_error)
38
make_exception_impl("TypeError",             type_error,              exception)
39
make_exception_impl("ValueError",            value_error,             exception)
40
make_exception_impl("RuntimeError",          runtime_error,           exception)
41
make_exception_impl("NotImplementedError",   not_implemented_error,   runtime_error)
42
make_exception_impl("EnvironmentError",      environment_error,       exception)
43
make_exception_impl("IOError",               io_error,                environment_error)
44
make_exception_impl("OSError",               os_error,                environment_error)
45
make_exception_impl("SystemError",           system_error,            exception)