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.
const std::string & getStringMessage() const
Reference access to the error message (can be empty).
std::string message
Error message (can be empty).
#define dgDEBUGOUT(level)
Definition: debug.h:204
#define dgDEBUGINOUT(level)
Definition: debug.h:206
const char * getMessage() const
Access to the pointer on the array of char related to the error string.
int getCode() const
Access to the error code.
virtual const std::string & getExceptionName() const
Abstract root class for all dynamic-graph exceptions.
Class owned by exceptions to store error locations.
static const std::string EXCEPTION_NAME
ExceptionAbstract()
Forbid the empty constructor (private).
DYNAMIC_GRAPH_DLLAPI friend std::ostream & operator<<(std::ostream &os, const ExceptionAbstract &err)
Print the error structure.
#define dgDEBUGIN(level)
VP_DEBUG.
Definition: debug.h:202


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Sun Jun 25 2023 02:06:03