exception-abstract.cpp
Go to the documentation of this file.
1 // Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
2 // JRL, CNRS/AIST.
3 //
4 
5 #include <dynamic-graph/debug.h>
7 
8 #include <cstring>
9 
10 namespace dynamicgraph {
11 const std::string ExceptionAbstract::EXCEPTION_NAME = "Abstract";
12 
13 ExceptionAbstract::ExceptionAbstract(const int &_code, const std::string &_msg)
14  : code(_code), message(_msg) {}
15 
16 const char *ExceptionAbstract::getMessage() const {
17  return (this->message).c_str();
18 }
19 
20 const std::string &ExceptionAbstract::getStringMessage() const {
21  return this->message;
22 }
23 
24 int ExceptionAbstract::getCode() const { return this->code; }
25 
27  if (&p == this) return *this;
28 
29  dgDEBUGIN(25);
30  if (p.pointersSet) {
31  strncpy(function, p.functionPTR, BUFFER_SIZE);
32  strncpy(file, p.filePTR, BUFFER_SIZE);
33  line = p.line;
34  pointersSet = false;
35  set = true;
36  } else
37  set = false;
38  dgDEBUGOUT(25);
39  return *this;
40 }
41 
42 ExceptionAbstract::Param::Param(const int &_line, const char *_function,
43  const char *_file)
44  : functionPTR(_function), line(_line), filePTR(_file), pointersSet(true) {
45  dgDEBUGINOUT(25);
46 }
47 
48 std::ostream &operator<<(std::ostream &os, const ExceptionAbstract &error) {
49  os << error.getExceptionName() << "Error [#" << error.code
50  << "]: " << 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  return os;
59 }
60 
61 } // end of namespace dynamicgraph.
dynamicgraph::ExceptionAbstract::Param::functionPTR
const char * functionPTR
Definition: exception-abstract.h:51
dynamicgraph::ExceptionAbstract::getStringMessage
const std::string & getStringMessage() const
Reference access to the error message (can be empty).
Definition: exception-abstract.cpp:20
dynamicgraph::ExceptionAbstract::Param
Class owned by exceptions to store error locations.
Definition: exception-abstract.h:36
dynamicgraph
dynamicgraph::ExceptionAbstract::Param::filePTR
const char * filePTR
Definition: exception-abstract.h:54
dynamicgraph::ExceptionAbstract::Param::BUFFER_SIZE
static const int BUFFER_SIZE
Definition: exception-abstract.h:38
dynamicgraph::ExceptionAbstract::code
int code
Error code.
Definition: exception-abstract.h:105
dynamicgraph::ExceptionAbstract::Param::file
char file[BUFFER_SIZE]
Definition: exception-abstract.h:55
dynamicgraph::ExceptionAbstract::Param::set
bool set
Definition: exception-abstract.h:57
dynamicgraph::ExceptionAbstract::Param::line
int line
Definition: exception-abstract.h:53
dynamicgraph::ExceptionAbstract
Abstract root class for all dynamic-graph exceptions.
Definition: exception-abstract.h:31
dgDEBUGOUT
#define dgDEBUGOUT(level)
Definition: debug.h:204
dynamicgraph::ExceptionAbstract::getCode
int getCode() const
Access to the error code.
Definition: exception-abstract.cpp:24
dgDEBUGIN
#define dgDEBUGIN(level)
VP_DEBUG.
Definition: debug.h:202
dynamicgraph::ExceptionAbstract::ExceptionAbstract
ExceptionAbstract()
Forbid the empty constructor (private).
dynamicgraph::ExceptionAbstract::operator<<
DYNAMIC_GRAPH_DLLAPI friend std::ostream & operator<<(std::ostream &os, const ExceptionAbstract &err)
Print the error structure.
Definition: exception-abstract.cpp:48
dynamicgraph::ExceptionAbstract::getMessage
const char * getMessage() const
Access to the pointer on the array of char related to the error string.
Definition: exception-abstract.cpp:16
dynamicgraph::ExceptionAbstract::Param::pointersSet
bool pointersSet
Definition: exception-abstract.h:56
dynamicgraph::ExceptionAbstract::EXCEPTION_NAME
static const std::string EXCEPTION_NAME
Definition: exception-abstract.h:75
dynamicgraph::ExceptionAbstract::message
std::string message
Error message (can be empty).
Definition: exception-abstract.h:108
dynamicgraph::ExceptionAbstract::Param::initCopy
Param & initCopy(const Param &p)
Definition: exception-abstract.cpp:26
dynamicgraph::ExceptionAbstract::Param::Param
Param()
Definition: exception-abstract.h:41
dgDEBUGINOUT
#define dgDEBUGINOUT(level)
Definition: debug.h:206
dynamicgraph::ExceptionAbstract::getExceptionName
virtual const std::string & getExceptionName() const
Definition: exception-abstract.h:80
debug.h
exception-abstract.h


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Sun Oct 22 2023 02:27:08