libsocket
exception.cpp
Go to the documentation of this file.
1 #include <errno.h>
2 #include <stdio.h>
3 #include <cstring>
4 #include <sstream>
5 #include <string>
6 
7 /*
8  The committers of the libsocket project, all rights reserved
9  (c) 2012, dermesser <lbo@spheniscida.de>
10 
11  Redistribution and use in source and binary forms, with or without
12  modification, are permitted provided that the following conditions are met:
13 
14  1. Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  2. Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19 
20  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS “AS IS” AND ANY
21  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
24  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 */
32 
53 #include <exception.hpp>
54 
55 namespace libsocket {
56 using std::string;
57 
67 socket_exception::socket_exception(const string& file, int line,
68  const string& message, bool show_errno) {
69  std::ostringstream message_stream;
70 
71  // Saving errno here should be safe
72  err = errno;
73 
74  message_stream << file << ":" << line << ": " << message;
75 
76  if (show_errno) message_stream << " (" << std::strerror(errno) << ")";
77 
78  message_stream << "\n";
79 
80  mesg = message_stream.str();
81 }
82 } // namespace libsocket
83 
Contains libsocket elements.
Definition: dgramclient.hpp:41
socket_exception(const string &file, int line, const string &message, bool show_errno=true)
Constructor of a socket_exception object.
Definition: exception.cpp:67
int err
This is the value of errno when the error occurred.
Definition: exception.hpp:53