Skip to content
Snippets Groups Projects
exception-abstract.cpp 1.62 KiB
Newer Older
Thomas Moulard's avatar
Thomas Moulard committed
// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
// JRL, CNRS/AIST.
//

#include <cstring>
#include <dynamic-graph/exception-abstract.h>
#include <dynamic-graph/debug.h>
Thomas Moulard's avatar
Thomas Moulard committed
namespace dynamicgraph {
Bergé's avatar
Bergé committed
const std::string ExceptionAbstract::EXCEPTION_NAME = "Abstract";
Bergé's avatar
Bergé committed
ExceptionAbstract::ExceptionAbstract(const int& _code, const std::string& _msg) : code(_code), message(_msg) {}
Bergé's avatar
Bergé committed
const char* ExceptionAbstract::getMessage() const { return (this->message).c_str(); }
Bergé's avatar
Bergé committed
const std::string& ExceptionAbstract::getStringMessage() const { return this->message; }
Bergé's avatar
Bergé committed
int ExceptionAbstract::getCode() const { return this->code; }
Bergé's avatar
Bergé committed
ExceptionAbstract::Param& ExceptionAbstract::Param::initCopy(const Param& p) {
  if (&p == this) return *this;
Bergé's avatar
Bergé committed
  dgDEBUGIN(25);
  if (p.pointersSet) {
    strncpy(function, p.functionPTR, BUFFER_SIZE);
    strncpy(file, p.filePTR, BUFFER_SIZE);
    line = p.line;
    pointersSet = false;
    set = true;
  } else
    set = false;
  dgDEBUGOUT(25);
  return *this;
}
Bergé's avatar
Bergé committed
ExceptionAbstract::Param::Param(const int& _line, const char* _function, const char* _file)
    : functionPTR(_function), line(_line), filePTR(_file), pointersSet(true) {
  dgDEBUGINOUT(25);
}
Thomas Moulard's avatar
Thomas Moulard committed

Bergé's avatar
Bergé committed
std::ostream& operator<<(std::ostream& os, const ExceptionAbstract& error) {
  os << error.getExceptionName() << "Error [#" << error.code << "]:  " << error.message << std::endl;
#ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
Bergé's avatar
Bergé committed
  if (error.p.set)
    os << "Thrown from " << error.p.file << ": " << error.p.function << " (#" << error.p.line << ")" << std::endl;
#endif  // DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
Bergé's avatar
Bergé committed
  return os;
}
Bergé's avatar
Bergé committed
}  // end of namespace dynamicgraph.