The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
libc_error.hpp
Go to the documentation of this file.
1 /*
2  By Ignacio Riquelme Morelle <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  The contents of this file are placed in the public domain.
6  */
7 
8 #include <exception>
9 #include <cerrno>
10 #include <cstring>
11 #include <string>
12 
13 #ifndef LIBC_ERROR_HPP_INCLUDED
14 #define LIBC_ERROR_HPP_INCLUDED
15 
16 /**
17  * Exception type used to propagate C runtime errors across functions.
18  */
19 class libc_error : public std::exception
20 {
21 public:
23  : e_(errno)
24  , desc_(strerror(e_))
25  , msg_("C library error: " + desc_)
26  {
27  }
28 
29  virtual ~libc_error() throw()
30  {
31  }
32 
33  /** Returns the value of @a errno at the time the exception was thrown. */
34  int num() const
35  {
36  return e_;
37  }
38 
39  /** Returns an explanatory string describing the runtime error alone. */
40  const std::string& desc() const
41  {
42  return desc_;
43  }
44 
45  /** Returns an explanatory string describing the exception. */
46  const char* what() const throw()
47  {
48  return msg_.c_str();
49  }
50 
51 private:
52  int e_;
55 };
56 
57 #endif
std::string msg_
Definition: libc_error.hpp:54
const std::string & desc() const
Returns an explanatory string describing the runtime error alone.
Definition: libc_error.hpp:40
const char * what() const
Returns an explanatory string describing the exception.
Definition: libc_error.hpp:46
Exception type used to propagate C runtime errors across functions.
Definition: libc_error.hpp:19
virtual ~libc_error()
Definition: libc_error.hpp:29
std::string desc_
Definition: libc_error.hpp:53
int num() const
Returns the value of errno at the time the exception was thrown.
Definition: libc_error.hpp:34
GLsizei const GLcharARB ** string
Definition: glew.h:4503