aGrUM  0.13.2
exceptions.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 #include <cstdio>
21 #include <iostream>
22 #include <sstream>
23 #include <string.h>
24 
25 #include <agrum/agrum.h>
26 #include <agrum/core/exceptions.h>
27 #ifndef NDEBUG
28 # ifdef HAVE_EXECINFO_H
29 # include <execinfo.h>
30 # endif // HAVE_EXECINFO_H
31 #endif // NDEBUG
32 
33 
34 #ifndef DOXYGEN_SHOULD_SKIP_THIS
35 
36 namespace gum {
37  const std::string __createMsg(const std::string& filename,
38  const std::string& function,
39  const int line,
40  const std::string& msg) {
41  std::stringstream stream;
42 # ifdef SWIG
43  stream << std::endl << msg << std::endl;
44 # else
45  stream << std::endl
46  << "<" << filename << "> " << function << "() #" << std::setw(6)
47  << std::dec << line << " :" << std::endl
48  << "--------------" << std::endl
49  << "! " << msg << std::endl
50  << "--------------" << std::endl;
51 # endif // SWIG
52  return stream.str();
53  }
54  Exception::Exception(const Exception& e) : _msg(e._msg), _type(e._type) {}
55 
56  Exception::Exception(const std::string aMsg, const std::string aType) :
57  _msg(aMsg), _type(aType) {
58 # ifndef NDEBUG
59 # ifdef HAVE_EXECINFO_H
60 # define callStackDepth 20
61  void* array[callStackDepth];
62  size_t size;
63  char** strings;
64  size = backtrace(array, callStackDepth);
65  strings = backtrace_symbols(array, size);
66 
67  std::stringstream stream;
68 
69  for (size_t i = 1; i < size; ++i) {
70  stream << i << " :" << strings[i] << std::endl;
71  }
72 
73  free(strings);
74  _callstack = stream.str();
75 # else // HAVE_EXECINFO_H
76  _callstack = "Callstack only in linux debug mode when execinfo.h available";
77 # endif // HAVE_EXECINFO_H
78 # else // NDEBUG
79  _callstack = "Callstack only in linux debug mod ewhen execinfo.h available";
80 # endif // NDEBUG
81  }
82 
83 } /* namespace gum */
84 
85 #endif // DOXYGEN_SHOULD_SKIP_THIS
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
aGrUM&#39;s exceptions
Exception(const std::string aMsg="", const std::string aType="Generic error")