MRPT  1.9.9
exceptions.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "core-precomp.h" // Precompiled headers
11 
12 #include <mrpt/core/exceptions.h>
13 
14 namespace mrpt::internal
15 {
17  const std::string_view& msg, const char* filename, unsigned int line,
18  const char* function_name)
19 {
20  std::string s;
21  s += filename;
22  s += ":";
23  s += std::to_string(line);
24  s += ": [";
25  s += function_name;
26  s += "] ";
27  s += msg;
28  s += "\n";
29  return s;
30 }
31 
32 /** Recursive implementation for mrpt::exception_to_str() */
33 void impl_excep_to_str(const std::exception& e, std::string& ret, int lvl = 0)
34 {
35  using namespace std::string_literals;
36  std::string err{e.what()};
37  if (!err.empty() && *err.rbegin() != '\n') err += "\n"s;
38  ret = "["s + std::to_string(lvl) + "] "s + err + ret;
39  try
40  {
41  std::rethrow_if_nested(e);
42  // We traversed the entire call stack,
43  // show just the original error message: "file:line: [func] MSG"
44  if (const auto idx = err.find("]"); idx != std::string::npos)
45  err = "Exception message: "s + err.substr(idx + 1);
46  ret = err + std::string("==== MRPT exception backtrace ====\n") + ret;
47  }
48  catch (const std::exception& er)
49  {
50  // It's nested: recursive call
51  impl_excep_to_str(er, ret, lvl + 1);
52  }
53  catch (...)
54  {
55  }
56 }
57 } // namespace mrpt::internal
58 
59 std::string mrpt::exception_to_str(const std::exception& e)
60 {
61  std::string descr;
63  return descr;
64 }
GLdouble s
Definition: glext.h:3682
GLsizei const GLchar ** string
Definition: glext.h:4116
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
Definition: exceptions.cpp:59
std::string exception_line_msg(const std::string_view &msg, const char *filename, unsigned int line, const char *function_name)
Definition: exceptions.cpp:16
std::string std::string to_string(T v)
Just like std::to_string(), but with an overloaded version for std::string arguments.
Definition: format.h:30
void impl_excep_to_str(const std::exception &e, std::string &ret, int lvl=0)
Recursive implementation for mrpt::exception_to_str()
Definition: exceptions.cpp:33



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019