sockpp
Modern C++ socket library wrapper
exception.h
Go to the documentation of this file.
1 
13 // --------------------------------------------------------------------------
14 // This file is part of the "sockpp" C++ socket library.
15 //
16 // Copyright (c) 2014-2017 Frank Pagliughi
17 // All rights reserved.
18 //
19 // Redistribution and use in source and binary forms, with or without
20 // modification, are permitted provided that the following conditions are
21 // met:
22 //
23 // 1. Redistributions of source code must retain the above copyright notice,
24 // this list of conditions and the following disclaimer.
25 //
26 // 2. Redistributions in binary form must reproduce the above copyright
27 // notice, this list of conditions and the following disclaimer in the
28 // documentation and/or other materials provided with the distribution.
29 //
30 // 3. Neither the name of the copyright holder nor the names of its
31 // contributors may be used to endorse or promote products derived from this
32 // software without specific prior written permission.
33 //
34 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
35 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
36 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
37 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
38 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
39 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
40 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
41 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
42 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
43 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
44 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 // --------------------------------------------------------------------------
46 
47 #ifndef __sockpp_exception_h
48 #define __sockpp_exception_h
49 
50 #include <cerrno>
51 #include <stdexcept>
52 #include <string>
53 
54 namespace sockpp {
55 
57 
64 class sys_error : public std::runtime_error
65 {
67  int errno_;
68 
69 public:
73  sys_error() : sys_error(errno) {}
78  explicit sys_error(int err);
83  int error() const { return errno_; }
90  static std::string error_str(int err);
91 };
92 
98 class getaddrinfo_error : public std::runtime_error
99 {
101  int error_;
103  std::string hostname_;
104 
105 public:
111  getaddrinfo_error(int err, const std::string &hostname);
116  int error() const { return error_; }
121  const std::string &hostname() const { return hostname_; }
122 };
123 
125 // end namespace 'sockpp'
126 }
127 
128 #endif // __sockpp_exception_h
129 
sys_error()
Creates an error using the current system &#39;errno&#39; value.
Definition: exception.h:73
static std::string error_str(int err)
Gets a string describing the specified error.
Errors from getaddrinfo.
Definition: exception.h:98
int error() const
Get the error number.
Definition: exception.h:116
System error.
Definition: exception.h:64
const std::string & hostname() const
Get the hostname that triggered the error.
Definition: exception.h:121
Definition: acceptor.h:51
int error() const
Get the error number.
Definition: exception.h:83