4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Exception public header */
27 #define HH_Exception_ 1
32 #include <boost/preprocessor/repeat.hpp>
33 #include <boost/preprocessor/cat.hpp>
35 //#include "Exception.mpp"
36 ///////////////////////////////hh.p////////////////////////////////////////
40 /** \brief Exception handling standard UNIX errors (errno)
42 This exception is thrown to signal generic \c errno failures. In addition to the \c errno
43 number (the code()), this class manages optional origin information. This parameter should
44 be provided to further describe, in what context the exception was created.
46 This exception should not be used directly. Instead the derived class ErrnoException should
47 be thrown via one of the senf::throwErrno() helpers.
51 class SystemException : public std::exception
54 SystemException(); ///< SystemException without error location infor
55 /**< The error code is taken from the current value of the
56 global \c errno variable */
58 explicit SystemException(int code); ///< SystemException without error location info
59 /**< \param[in] code error number (the \c errno value) */
61 explicit SystemException(char const * where); ///< SystemException with error location info
62 /**< The error code is taken from the current value of the
63 global \c errno variable
64 \param[in] where description of error origin */
66 SystemException(char const * where, int code); ///< SystemException with error location info
67 /**< \param[in] where description of error origin
68 \param[in] code error number (the \c errno value) */
70 virtual char const * what() const throw(); ///< Return verbose error description
72 char const * where() const; ///< Error origin
73 int code() const; ///< Error code (\c errno number)
74 char const * description() const; ///< Error description (strerror() value)
76 bool anyOf(int c0, int c1=0, int c2=0, int c3=0, int c4=0, int c5=0,
77 int c6=0, int c7=0, int c8=0, int c9=0);
78 ///< \c true, if code() is one of \a c0 ... \a c9
80 virtual ~SystemException() throw();
85 char const * const where_;
86 int const code_; // This must be const to make the derived ErrnoException
87 // class a valid derived class.
91 /** \brief Error specific system exception
93 This template restricts the generic SystemException to a specific, compile-time constant
94 error number \p Code. This allows a specific \c errno number to be cached explicitly.
96 This exception is normally thrown via one of the senf::throwErrno() helpers. These helpers
97 take the numeric \c errno value (either from the \c errno variable or from their
98 argument) and will throw the corresponding ErrnoException:
100 if ((fd = ::open(filename, O_RDWR)) < 0)
101 senf::throwErrno("open()");
105 class ErrnoException : public SystemException
108 static int const fixed_code = Code;
110 ErrnoException(); ///< ErrnoException without error location information
111 explicit ErrnoException(char const * where);
112 ///< ErrnoException with error location information
116 /** \brief Throw ErrnoException based on current \c errno value
117 \related ErrnoException
121 /** \brief Throw ErrnoException based on current \c errno value (with location info)
122 \related ErrnoException
124 void throwErrno(char const * where);
126 /** \brief Throw ErrnoException based on given \c errno value
127 \related ErrnoException
129 void throwErrno(int code);
131 /** \brief Throw ErrnoException based on given \c errno value (with location info)
132 \related ErrnoException
134 void throwErrno(char const * where, int code);
136 enum NoThrow_t { nothrow };
140 ///////////////////////////////hh.e////////////////////////////////////////
141 #include "Exception.cci"
142 //#include "Exception.ct"
143 #include "Exception.cti"
150 // c-file-style: "senf"
151 // indent-tabs-mode: nil
152 // ispell-local-dictionary: "american"
153 // compile-command: "scons -u test"
154 // comment-column: 40