aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
exceptions.cpp
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2026 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
42#include <cstdlib>
43
44#include <agrum/agrum.h>
45
47#ifdef GUM_NO_INLINE
49#endif // GUM_NO_INLINE
50#ifdef GUM_DEBUG_MODE
51# ifdef HAVE_EXECINFO_H
52# include <execinfo.h>
53# endif // HAVE_EXECINFO_H
54#endif // GUM_DEBUG_MODE
55
56
57#ifndef DOXYGEN_SHOULD_SKIP_THIS
58
59namespace gum {
60 std::string _createMsg_(std::string_view filename,
61 std::string_view function,
62 const int line,
63 std::string_view msg) {
64# ifdef GUM_FOR_SWIG
65 return std::format("\n{}\n", msg);
66# else // GUM_FOR_SWIG
67 return std::format("\n{}:{} in {}()\n--------------\n! {}\n--------------\n",
68 filename,
69 line,
70 function,
71 msg);
72# endif // GUM_FOR_SWIG
73 }
74
76 std::exception(e), msg_(e.msg_), type_(e.type_), what_(e.what_) {}
77
78 Exception::Exception(std::string_view aMsg, std::string_view aType) :
79 std::exception(), msg_(aMsg), type_(aType) {
80# ifdef GUM_FOR_SWIG
81 what_ = "[pyAgrum] " + type_ + ": " + msg_;
82# else // GUM_FOR_SWIG
83 what_ = type_ + ": " + msg_;
84# endif // GUM_FOR_SWIG
85
86# ifdef GUM_DEBUG_MODE
87# ifdef HAVE_EXECINFO_H
88# define callStackDepth 20
89 void* array[callStackDepth];
90 size_t size;
91 char** strings;
92 size = backtrace(array, callStackDepth);
93 strings = backtrace_symbols(array, size);
94
95 std::string callstack_str;
96
97 for (size_t i = 1; i < size; ++i) {
98 callstack_str += std::format("{} :{}\n", i, strings[i]);
99 }
100
101 free(strings);
102 callstack_ = callstack_str;
103# else // HAVE_EXECINFO_H
104 callstack_ = "Callstack only in linux debug mode when execinfo.h available";
105# endif // HAVE_EXECINFO_H
106# else // GUM_DEBUG_MODE
107 callstack_ = "Callstack only in linux debug mod ewhen execinfo.h available";
108# endif // GUM_DEBUG_MODE
109 }
110
111} /* namespace gum */
112
113#endif // DOXYGEN_SHOULD_SKIP_THIS
Base class for all aGrUM's exceptions.
Definition exceptions.h:122
Exception(std::string_view aMsg="", std::string_view aType="Generic error")
aGrUM's exceptions
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
STL namespace.