1 |
|
|
// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse, |
2 |
|
|
// JRL, CNRS/AIST. |
3 |
|
|
// |
4 |
|
|
|
5 |
|
|
#include <dynamic-graph/debug.h> |
6 |
|
|
#include <dynamic-graph/exception-abstract.h> |
7 |
|
|
|
8 |
|
|
#include <cstring> |
9 |
|
|
|
10 |
|
|
namespace dynamicgraph { |
11 |
|
|
const std::string ExceptionAbstract::EXCEPTION_NAME = "Abstract"; |
12 |
|
|
|
13 |
|
64 |
ExceptionAbstract::ExceptionAbstract(const int &_code, const std::string &_msg) |
14 |
✓✗ |
64 |
: code(_code), message(_msg) {} |
15 |
|
|
|
16 |
|
1 |
const char *ExceptionAbstract::getMessage() const { |
17 |
|
1 |
return (this->message).c_str(); |
18 |
|
|
} |
19 |
|
|
|
20 |
|
1 |
const std::string &ExceptionAbstract::getStringMessage() const { |
21 |
|
1 |
return this->message; |
22 |
|
|
} |
23 |
|
|
|
24 |
|
39 |
int ExceptionAbstract::getCode() const { return this->code; } |
25 |
|
|
|
26 |
|
1 |
ExceptionAbstract::Param &ExceptionAbstract::Param::initCopy(const Param &p) { |
27 |
✗✓ |
1 |
if (&p == this) return *this; |
28 |
|
|
|
29 |
|
|
dgDEBUGIN(25); |
30 |
✓✗ |
1 |
if (p.pointersSet) { |
31 |
|
1 |
strncpy(function, p.functionPTR, BUFFER_SIZE); |
32 |
|
1 |
strncpy(file, p.filePTR, BUFFER_SIZE); |
33 |
|
1 |
line = p.line; |
34 |
|
1 |
pointersSet = false; |
35 |
|
1 |
set = true; |
36 |
|
|
} else |
37 |
|
|
set = false; |
38 |
|
|
dgDEBUGOUT(25); |
39 |
|
1 |
return *this; |
40 |
|
|
} |
41 |
|
|
|
42 |
|
1 |
ExceptionAbstract::Param::Param(const int &_line, const char *_function, |
43 |
|
1 |
const char *_file) |
44 |
|
1 |
: functionPTR(_function), line(_line), filePTR(_file), pointersSet(true) { |
45 |
|
|
dgDEBUGINOUT(25); |
46 |
|
1 |
} |
47 |
|
|
|
48 |
|
3 |
std::ostream &operator<<(std::ostream &os, const ExceptionAbstract &error) { |
49 |
|
3 |
os << error.getExceptionName() << "Error [#" << error.code |
50 |
|
3 |
<< "]: " << error.message << std::endl; |
51 |
|
|
|
52 |
|
|
#ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM |
53 |
|
|
if (error.p.set) |
54 |
|
|
os << "Thrown from " << error.p.file << ": " << error.p.function << " (#" |
55 |
|
|
<< error.p.line << ")" << std::endl; |
56 |
|
|
#endif // DYNAMICGRAPH_EXCEPTION_PASSING_PARAM |
57 |
|
|
|
58 |
|
3 |
return os; |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
} // end of namespace dynamicgraph. |