1 |
|
|
/** |
2 |
|
|
* @file exception-abstract.cpp |
3 |
|
|
* @author Maximilien Naveau (maximilien.naveau@gmail.com) |
4 |
|
|
* @license License BSD-3-Clause |
5 |
|
|
* @copyright Copyright (c) 2019, New York University and Max Planck Gesellschaft. |
6 |
|
|
* @date 2019-05-22 |
7 |
|
|
*/ |
8 |
|
|
|
9 |
|
|
#include <dynamic-graph/debug.h> |
10 |
|
|
|
11 |
|
|
#include <dynamic_graph_manager/exception/exception-abstract.hh> |
12 |
|
|
|
13 |
|
|
using namespace std; |
14 |
|
|
using namespace dynamic_graph; |
15 |
|
|
|
16 |
|
|
/* ------------------------------------------------------------------------- */ |
17 |
|
|
/* --- CONSTRUCTORS -------------------------------------------------------- */ |
18 |
|
|
/* ------------------------------------------------------------------------- */ |
19 |
|
|
|
20 |
✓✗ |
4 |
const std::string ExceptionAbstract::EXCEPTION_NAME = "Abstract"; |
21 |
|
|
|
22 |
|
|
|
23 |
|
4 |
ExceptionAbstract::ExceptionAbstract (const int& _code, const string & _msg): |
24 |
|
|
code (_code), |
25 |
✓✗ |
4 |
message (_msg) |
26 |
|
|
{ |
27 |
|
4 |
return ; |
28 |
|
|
} |
29 |
|
|
|
30 |
|
|
/* ------------------------------------------------------------------------ */ |
31 |
|
|
/* --- ACCESSORS ---------------------------------------------------------- */ |
32 |
|
|
/* ------------------------------------------------------------------------ */ |
33 |
|
|
|
34 |
|
|
const char *ExceptionAbstract::getMessage (void) |
35 |
|
|
{ |
36 |
|
|
return (this->message) .c_str(); |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
const string &ExceptionAbstract::getStringMessage (void) |
40 |
|
|
{ |
41 |
|
|
return this->message; |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
int ExceptionAbstract::getCode (void) |
45 |
|
|
{ |
46 |
|
|
return this->code; |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
const char* ExceptionAbstract::what() const throw() |
50 |
|
|
{ |
51 |
|
|
return message.c_str(); |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
/* ------------------------------------------------------------------------- */ |
55 |
|
|
/* --- MODIFIORS ----------------------------------------------------------- */ |
56 |
|
|
/* ------------------------------------------------------------------------- */ |
57 |
|
|
#ifdef SOT_EXCEPTION_PASSING_PARAM |
58 |
|
|
|
59 |
|
|
|
60 |
|
|
ExceptionAbstract::Param& ExceptionAbstract::Param:: |
61 |
|
|
initCopy( const Param& p ) |
62 |
|
|
{ |
63 |
|
|
sotDEBUGIN(25); |
64 |
|
|
if( p.pointersSet ) |
65 |
|
|
{ |
66 |
|
|
strncpy( function,p.functionPTR,BUFFER_SIZE); |
67 |
|
|
strncpy( file,p.filePTR,BUFFER_SIZE); |
68 |
|
|
line = p.line; |
69 |
|
|
pointersSet=false; |
70 |
|
|
set=true; |
71 |
|
|
} else set=false; |
72 |
|
|
sotDEBUGOUT(25); |
73 |
|
|
return *this; |
74 |
|
|
} |
75 |
|
|
ExceptionAbstract::Param:: |
76 |
|
|
Param( const int& _line, const char * _function, const char * _file ) |
77 |
|
|
: functionPTR(_function),line(_line),filePTR(_file),pointersSet(true) |
78 |
|
|
{ |
79 |
|
|
sotDEBUGINOUT(25); |
80 |
|
|
} |
81 |
|
|
#endif //#ifdef SOT_EXCEPTION_PASSING_PARAM |
82 |
|
|
|
83 |
|
|
/* ------------------------------------------------------------------------- */ |
84 |
|
|
/* --- OP << --------------------------------------------------------------- */ |
85 |
|
|
/* ------------------------------------------------------------------------- */ |
86 |
|
|
|
87 |
|
|
namespace dynamic_graph { |
88 |
|
|
ostream & operator << (ostream & os, const ExceptionAbstract & error) |
89 |
|
|
{ |
90 |
|
|
os << error.getExceptionName() |
91 |
|
|
<< "Error [#" << error.code << "]: " |
92 |
|
|
<< error.message |
93 |
|
|
<< endl; |
94 |
|
|
|
95 |
|
|
#ifdef SOT_EXCEPTION_PASSING_PARAM |
96 |
|
|
if( error.p.set ) |
97 |
|
|
os << "Thrown from "<<error.p.file << ": "<<error.p.function |
98 |
|
|
<<" (#"<<error.p.line << ")"<<endl; |
99 |
|
|
#endif //#ifdef SOT_EXCEPTION_PASSING_PARAM |
100 |
|
|
return os; |
101 |
|
|
} |
102 |
✓✗✓✗
|
12 |
} // namespace dynamic_graph |
103 |
|
|
|
104 |
|
|
/** \file $Source$ |
105 |
|
|
*/ |
106 |
|
|
|
107 |
|
|
/* |
108 |
|
|
* Local variables: |
109 |
|
|
* c-basic-offset: 2 |
110 |
|
|
* End: |
111 |
|
|
*/ |