added an exception class for my ULE decoder
[senf.git] / Utils / Exception.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief Exception public header */
25
26 #ifndef HH_Exception_
27 #define HH_Exception_ 1
28
29 // Custom includes
30 #include <exception>
31 #include <string>
32
33 //#include "Exception.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
35
36 namespace senf {
37
38     /** \brief Exception handling standard UNIX errors (errno)
39
40         This exception is thrown to signal generic errno failures.
41
42         \todo make where and err accessors and make the member vars private
43
44         \idea Add a template class derived from SystemException which
45         takes the error number as a numeric argument. This allows
46         catching specific errno conditions: ErrnoException<EPIPE> etc.
47
48         \idea Add a generic error thrower which takes the origin
49         string and errno value as an argument and will throw a
50         corresponding template class instance. This would just be a
51         big switch statement containing all possible errno values,
52         probably created using some macro metaprogramming.
53      */
54     class SystemException : public std::exception
55     {
56     public:
57         explicit SystemException(int err); ///< SystemException without error lokus info
58                                         /**< \param[in] err error number (the errno value) */
59         SystemException(char const * where, int err); ///< SystemException with error location info
60                                         /**< \param[in] where description of error origin
61                                              \param[in] err error number (the errno value) */
62
63         virtual char const * what() const throw(); ///< Return verbose error description
64
65         char const * where; ///< Error origin
66         int err; ///< Error number
67
68         virtual ~SystemException() throw();
69     private:
70         void init();
71         std::string buffer_;
72     };
73
74     enum NoThrow_t { nothrow };
75
76 }
77
78 ///////////////////////////////hh.e////////////////////////////////////////
79 #include "Exception.cci"
80 //#include "Exception.ct"
81 //#include "Exception.cti"
82 #endif
83
84 \f
85 // Local Variables:
86 // mode: c++
87 // fill-column: 100
88 // c-file-style: "senf"
89 // indent-tabs-mode: nil
90 // ispell-local-dictionary: "american"
91 // compile-command: "scons -u test"
92 // comment-column: 40
93 // End: