Line |
Branch |
Exec |
Source |
1 |
|
|
// Copyright (C) 2010 by Thomas Moulard, CNRS. |
2 |
|
|
// |
3 |
|
|
|
4 |
|
|
// Redistribution and use in source and binary forms, with or without |
5 |
|
|
// modification, are permitted provided that the following conditions are |
6 |
|
|
// met: |
7 |
|
|
// |
8 |
|
|
// 1. Redistributions of source code must retain the above copyright |
9 |
|
|
// notice, this list of conditions and the following disclaimer. |
10 |
|
|
// |
11 |
|
|
// 2. Redistributions in binary form must reproduce the above copyright |
12 |
|
|
// notice, this list of conditions and the following disclaimer in the |
13 |
|
|
// documentation and/or other materials provided with the distribution. |
14 |
|
|
// |
15 |
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
16 |
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
17 |
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
18 |
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
19 |
|
|
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
20 |
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
21 |
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 |
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 |
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 |
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
25 |
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
26 |
|
|
// DAMAGE. |
27 |
|
|
// |
28 |
|
|
// This software is provided "as is" without warranty of any kind, |
29 |
|
|
// either expressed or implied, including but not limited to the |
30 |
|
|
// implied warranties of fitness for a particular purpose. |
31 |
|
|
// |
32 |
|
|
// See the COPYING file for more information. |
33 |
|
|
|
34 |
|
|
#include <iostream> |
35 |
|
|
|
36 |
|
|
#ifdef HPP_LOG_EXCEPTION |
37 |
|
|
#include "hpp/util/debug.hh" |
38 |
|
|
#endif // HPP_LOG_EXCEPTION |
39 |
|
|
|
40 |
|
|
#include "hpp/util/exception.hh" |
41 |
|
|
|
42 |
|
|
namespace hpp { |
43 |
|
7 |
Exception::Exception(const std::string& message, const std::string& file, |
44 |
|
7 |
unsigned line) throw() |
45 |
|
7 |
: std::exception(), message_(message), file_(file), line_(line) { |
46 |
|
|
// Allow to transparently log created exceptions. |
47 |
|
|
#ifdef HPP_LOG_EXCEPTION |
48 |
|
|
hppDout(info, *this); |
49 |
|
|
#endif // HPP_LOG_EXCEPTION |
50 |
|
7 |
} |
51 |
|
|
|
52 |
|
14 |
Exception::~Exception() throw() {} |
53 |
|
|
|
54 |
|
✗ |
Exception::Exception(const Exception& exception) throw() |
55 |
|
|
: std::exception(), |
56 |
|
✗ |
message_(exception.message_), |
57 |
|
✗ |
file_(exception.file_), |
58 |
|
✗ |
line_(exception.line_) {} |
59 |
|
|
|
60 |
|
✗ |
Exception& Exception::operator=(const Exception& exception) throw() { |
61 |
|
✗ |
if (&exception == this) return *this; |
62 |
|
|
|
63 |
|
✗ |
message_ = exception.message_; |
64 |
|
✗ |
file_ = exception.file_; |
65 |
|
✗ |
line_ = exception.line_; |
66 |
|
✗ |
return *this; |
67 |
|
|
} |
68 |
|
|
|
69 |
|
✗ |
const char* Exception::what() const throw() { |
70 |
|
|
// FIXME: display line and file too. |
71 |
|
✗ |
return message_.c_str(); |
72 |
|
|
} |
73 |
|
|
|
74 |
|
7 |
std::ostream& Exception::print(std::ostream& o) const throw() { |
75 |
|
7 |
o << file_ << ':' << line_ << ": " << message_; |
76 |
|
7 |
return o; |
77 |
|
|
} |
78 |
|
|
|
79 |
|
7 |
std::ostream& operator<<(std::ostream& o, const Exception& exception) { |
80 |
|
7 |
exception.print(o); |
81 |
|
7 |
return o; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
} // end of namespace hpp. |
85 |
|
|
|