exception_tracer.cpp
Go to the documentation of this file.
1 
17 /*****************************************************************************
18 ** Cross Platform
19 *****************************************************************************/
20 
21 #include <ecl/config/ecl.hpp>
22 
23 #ifndef ECL_IS_WIN32
24 
25 /*****************************************************************************
26 ** Includes
27 *****************************************************************************/
28 
29 #include <execinfo.h> // backtrace
30 #include <signal.h>
31 #include <cstdlib>
32 #include <exception>
33 #include <iostream>
34 
35 /*****************************************************************************
36 ** Exceptions
37 *****************************************************************************/
38 
42 class ExceptionTracer {
43 public:
44  ExceptionTracer() {
45  void * array[25];
46  int nSize = backtrace(array, 25);
47  char ** symbols = backtrace_symbols(array, nSize);
48 
49  for (int i = 0; i < nSize; i++) {
50  std::cout << symbols[i] << std::endl;
51  }
52  free(symbols);
53  }
54 };
55 
56 void f() {
57  std::cout << "f()" << std::endl;
58  throw ExceptionTracer();
59 }
60 /*****************************************************************************
61 ** Main
62 *****************************************************************************/
63 
64 int main(int argc, char **argv) {
65 
66  std::cout << "Dude" << std::endl;
67  f();
68 
69  return 0;
70 }
71 #else
72 
73 #include <iostream>
74 
75 int main(int argc, char **argv) {
76 
77  std::cout << "No backtrace support in windows (that I know of yet)." << std::endl;
78  return 0;
79 }
80 #endif
81 
int main(int argc, char **argv)
Definition: exceptions.cpp:55
void f(int i)
Definition: exceptions.cpp:42


ecl_exceptions
Author(s): Daniel Stonier
autogenerated on Mon Feb 28 2022 22:18:26