d97c9ab3bfef2944b0f43986462096a9f30ef737
[senf.git] / senf / Utils / Exception.cci
1 // $Id$
2 //
3 // Copyright (C) 2006 Stefan Bund <g0dil@senf.berlios.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the
17 // Free Software Foundation, Inc.,
18 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 /** \file
21     \brief Exception inline non-template implementation */
22
23 // Custom includes
24 #include <errno.h>
25 #include <cstring>
26
27 #define prefix_ inline
28 //-/////////////////////////////////////////////////////////////////////////////////////////////////
29
30 //-/////////////////////////////////////////////////////////////////////////////////////////////////
31 // senf::ExceptionMixin
32
33 prefix_ senf::ExceptionMixin::ExceptionMixin(std::string const & description)
34     : what_(description)
35 {
36 #ifdef SENF_DEBUG
37     addBacktrace();
38 #endif
39 }
40
41 prefix_ std::string senf::ExceptionMixin::message()
42     const
43 {
44 #ifdef SENF_DEBUG
45     return what_.substr(excLen_);
46 #else
47     return what_;
48 #endif
49 }
50
51 prefix_ std::string senf::ExceptionMixin::backtrace()
52     const
53 {
54 #ifdef SENF_DEBUG
55     return what_.substr(0,excLen_-4);
56 #else
57     return "";
58 #endif
59 }
60
61 prefix_ void senf::ExceptionMixin::append(std::string text)
62 {
63     what_ += text;
64 }
65
66 //-/////////////////////////////////////////////////////////////////////////////////////////////////
67 // senf::Exception
68
69 prefix_ senf::Exception::Exception(std::string const & description)
70     : ExceptionMixin(description)
71 {}
72
73 //-/////////////////////////////////////////////////////////////////////////////////////////////////
74 // senf::SystemException
75
76 prefix_ senf::SystemException::SystemException(std::string const & descr _SENF_EXC_DEBUG_ARGS_ND)
77 {
78     init(descr, errno _SENF_EXC_DEBUG_ARGS_P);
79 }
80
81 prefix_ senf::SystemException::SystemException(int code _SENF_EXC_DEBUG_ARGS_ND)
82 {
83     init("", code _SENF_EXC_DEBUG_ARGS_P);
84 }
85
86 prefix_ senf::SystemException::SystemException(std::string const & descr, int code
87                                                _SENF_EXC_DEBUG_ARGS_ND)
88 {
89     init(descr, code _SENF_EXC_DEBUG_ARGS_P);
90 }
91
92 prefix_ int senf::SystemException::errorNumber()
93     const
94 {
95     return code_;
96 }
97
98 prefix_ char const * senf::SystemException::errorString()
99     const
100 {
101     return std::strerror(code_);
102 }
103
104 prefix_ bool senf::SystemException::anyOf(int c0, int c1, int c2, int c3, int c4, int c5,
105                                           int c6, int c7, int c8, int c9)
106     const
107 {
108     return
109         (c0 && code_ == c0) ||
110         (c1 && code_ == c1) ||
111         (c2 && code_ == c2) ||
112         (c3 && code_ == c3) ||
113         (c4 && code_ == c4) ||
114         (c5 && code_ == c5) ||
115         (c6 && code_ == c6) ||
116         (c7 && code_ == c7) ||
117         (c8 && code_ == c8) ||
118         (c9 && code_ == c9);
119 }
120
121 prefix_  senf::SystemException::~SystemException()
122     throw()
123 {}
124
125 //-/////////////////////////////////////////////////////////////////////////////////////////////////
126 #undef prefix_
127
128 \f
129 // Local Variables:
130 // mode: c++
131 // fill-column: 100
132 // c-file-style: "senf"
133 // indent-tabs-mode: nil
134 // ispell-local-dictionary: "american"
135 // compile-command: "scons -u test"
136 // comment-column: 40
137 // End: