aGrUM  0.16.0
exceptions.cpp
Go to the documentation of this file.
1 
23 #include <cstdio>
24 #include <iostream>
25 #include <sstream>
26 #include <string.h>
27 
28 #include <agrum/agrum.h>
29 #include <agrum/core/exceptions.h>
30 #ifdef GUM_DEBUG_MODE
31 # ifdef HAVE_EXECINFO_H
32 # include <execinfo.h>
33 # endif // HAVE_EXECINFO_H
34 #endif // GUM_DEBUG_MODE
35 
36 
37 #ifndef DOXYGEN_SHOULD_SKIP_THIS
38 
39 namespace gum {
40  const std::string __createMsg(const std::string& filename,
41  const std::string& function,
42  const int line,
43  const std::string& msg) {
44  std::stringstream stream;
45 # ifdef SWIG
46  stream << std::endl << msg << std::endl;
47 # else
48  stream << std::endl
49  << "<" << filename << "> " << function << "() #" << std::setw(6)
50  << std::dec << line << " :" << std::endl
51  << "--------------" << std::endl
52  << "! " << msg << std::endl
53  << "--------------" << std::endl;
54 # endif // SWIG
55  return stream.str();
56  }
57  Exception::Exception(const Exception& e) : _msg(e._msg), _type(e._type) {}
58 
59  Exception::Exception(const std::string aMsg, const std::string aType) :
60  _msg(aMsg), _type(aType) {
61 # ifdef GUM_DEBUG_MODE
62 # ifdef HAVE_EXECINFO_H
63 # define callStackDepth 20
64  void* array[callStackDepth];
65  size_t size;
66  char** strings;
67  size = backtrace(array, callStackDepth);
68  strings = backtrace_symbols(array, size);
69 
70  std::stringstream stream;
71 
72  for (size_t i = 1; i < size; ++i) {
73  stream << i << " :" << strings[i] << std::endl;
74  }
75 
76  free(strings);
77  _callstack = stream.str();
78 # else // HAVE_EXECINFO_H
79  _callstack = "Callstack only in linux debug mode when execinfo.h available";
80 # endif // HAVE_EXECINFO_H
81 # else // GUM_DEBUG_MODE
82  _callstack = "Callstack only in linux debug mod ewhen execinfo.h available";
83 # endif // GUM_DEBUG_MODE
84  }
85 
86 } /* namespace gum */
87 
88 #endif // DOXYGEN_SHOULD_SKIP_THIS
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Exception(const std::string aMsg="", const std::string aType="Generic error")