artdaq_core  v3_06_10
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 #include "cetlib_except/exception.h"
6 
7 #define TRACE_NAME "ExceptionStackTrace_t"
8 #include "tracemf.h"
9 
10 BOOST_AUTO_TEST_SUITE(ExceptionStackTrace_test)
11 
12 
15 void PrintExceptionStackTrace()
16 {
17  auto message = artdaq::debug::getStackTraceCollector().print_stacktrace();
18 
19  std::string::size_type pos = 0;
20  std::string::size_type prev = 0;
21 
22  while ((pos = message.find('\n', prev)) != std::string::npos)
23  {
24  TLOG(TLVL_DEBUG) << message.substr(prev, pos - prev);
25  prev = pos + 1;
26  }
27 
28  TLOG(TLVL_DEBUG) << message.substr(prev);
29 }
30 
31 BOOST_AUTO_TEST_CASE(PrintStackTrace)
32 {
33  try
34  {
35  throw int(5);
36  }
37  catch (int)
38  {
39  PrintExceptionStackTrace();
40  }
41 }
42 
43 BOOST_AUTO_TEST_SUITE_END()
std::string print_stacktrace()
Produces a stack trace summary.