systemerror.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004-2007 Marc Boris Duerner
3  * Copyright (C) 2005-2007 Aloysius Indrayanto
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * As a special exception, you may use this file as part of a free
11  * software library without restriction. Specifically, if other files
12  * instantiate templates or use macros or inline functions from this
13  * file, or you compile this file and link it with other files to
14  * produce an executable, this file does not by itself cause the
15  * resulting executable to be covered by the GNU General Public
16  * License. This exception does not however invalidate any other
17  * reasons why the executable file might be covered by the GNU Library
18  * General Public License.
19  *
20  * This library is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23  * Lesser General Public License for more details.
24  *
25  * You should have received a copy of the GNU Lesser General Public
26  * License along with this library; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28  */
29 #ifndef CXXTOOLS_SYSTEM_ERROR_H
30 #define CXXTOOLS_SYSTEM_ERROR_H
31 
32 #include <stdexcept>
33 #include <string>
34 
35 namespace cxxtools
36 {
37 
40 class SystemError : public std::runtime_error
41 {
42  protected:
43  explicit SystemError(const std::string& msg);
44 
45  public:
46  SystemError(int err, const char* fn);
47 
48  explicit SystemError(const char* fn);
49 
50  SystemError(const char* fn, const std::string& msg);
51 
52  ~SystemError() throw();
53 
54  int getErrno() const
55  { return m_errno; }
56 
57  private:
58  int m_errno;
59 };
60 
61 void throwSystemError(const char* fn);
62 
63 void throwSystemError(int errnum, const char* fn);
64 
68 {
69  std::string _library;
70 
71  public:
73  explicit OpenLibraryFailed(const std::string& library);
74 
77  {}
78 
79  const std::string& library() const
80  { return _library; }
81 };
82 
86 {
87  std::string _symbol;
88 
89  public:
90  explicit SymbolNotFound(const std::string& sym);
91 
93  ~SymbolNotFound() throw()
94  {}
95 
97  const std::string& symbol() const
98  { return _symbol; }
99 };
100 
101 class SslError : public SystemError
102 {
103  public:
104  SslError(const std::string& msg, unsigned long sslError)
105  : SystemError(msg),
106  _sslError(sslError)
107  { }
108 
109  unsigned long getSslError() const
110  { return _sslError; }
111  private:
112  unsigned long _sslError;
113 };
114 
115 } // namespace cxxtools
116 
117 #endif