artdaq_core  v3_09_00
ExceptionStackTrace_t.cc
1 #include "artdaq-core/Utilities/ExceptionStackTrace.hh"
2 
3 #define BOOST_TEST_MODULE ExceptionStackTrace_t
4 #include "cetlib/quiet_unit_test.hpp"
5 
6 #define TRACE_NAME "ExceptionStackTrace_t"
7 #include "TRACE/tracemf.h"
8 
9 BOOST_AUTO_TEST_SUITE(ExceptionStackTrace_test)
10 
11 
14 void PrintExceptionStackTrace()
15 {
16  auto message = artdaq::debug::getStackTraceCollector().print_stacktrace();
17 
18  std::string::size_type pos = 0;
19  std::string::size_type prev = 0;
20 
21  while ((pos = message.find('\n', prev)) != std::string::npos)
22  {
23  TLOG(TLVL_DEBUG) << message.substr(prev, pos - prev);
24  prev = pos + 1;
25  }
26 
27  TLOG(TLVL_DEBUG) << message.substr(prev);
28 }
29 
30 BOOST_AUTO_TEST_CASE(PrintStackTrace)
31 {
32  try
33  {
34  throw int(5);
35  }
36  catch (int)
37  {
38  PrintExceptionStackTrace();
39  }
40 }
41 
42 BOOST_AUTO_TEST_SUITE_END()
std::string print_stacktrace()
Produces a stack trace summary.