journalexception.h
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32 
33 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
65 #ifndef JOURNALEXCEPTION_H
66 #define JOURNALEXCEPTION_H
67 
68 #include <string>
69 #include <xstypes/xsexception.h>
70 
71 #include "journaller.h"
72 
73 #ifndef XSENS_WINDOWS
74  #include <signal.h>
75  #include <cstring>
76 #endif
77 
78 class JournalException : public XsException
79 {
80 public:
81  JournalException(std::string const& message);
82  ~JournalException() throw() {}
83 
84  const char* msg() const;
85  const std::string& stack() const;
86 
87 protected:
88  std::string m_stack;
90 };
91 
93 #define JLTHROW(msg) do { std::ostringstream os; os << msg; throw JournalException(os.str()); } while(0)
94 
95 extern bool gOnExceptionGotoDebugger;
96 
97 #ifdef XSENS_WINDOWS
98  #include <windows.h>
99  LONG journallerExceptionFilter(EXCEPTION_POINTERS* pExPtrs, Journaller*);
100 #endif
101 
102 #if JLDEF_BUILD > JLL_FATAL
103 #define JOURNALCRASHES_SIGNAL_FUNCTIONS
104 #define JOURNALCRASHES_BEGIN(journal)
105 #define JOURNALCRASHES_END(journal)
106 #else
107 #ifdef XSENS_WINDOWS
108 #define JOURNALCRASHES_SIGNAL_FUNCTIONS
109 #define JOURNALCRASHES_BEGIN(journal) \
110  __try {
111 
112 #define JOURNALCRASHES_END(journal) \
113  } __except (journallerExceptionFilter(GetExceptionInformation(), journal)) {}
114 
115 #else
116 #define JOURNALCRASHES_SIGNAL_FUNCTIONS \
117  Journaller *gSCJ = 0;\
118  extern "C" void signal_handler(int signal, siginfo_t *, void *)\
119  {\
120  if (gSCJ)\
121  {\
122  JLFATAL_NODEC(gSCJ, strsignal(signal));\
123  gSCJ->writeCallstack(JLL_Fatal);\
124  }\
125  _exit(-1);\
126  }
127 
128 #define JOURNALCRASHES_BEGIN(journal) \
129  do { \
130  gSCJ = journal;\
131  struct sigaction act;\
132  memset(&act, 0, sizeof(act));\
133  act.sa_flags = SA_SIGINFO;\
134  act.sa_sigaction = &signal_handler;\
135  sigaction(SIGSEGV, &act, NULL);\
136  sigaction(SIGILL, &act, NULL);\
137  sigaction(SIGABRT, &act, NULL);\
138  sigaction(SIGFPE, &act, NULL);\
139  } while (0);
140 #define JOURNALCRASHES_END(journal)
141 #endif
142 #endif
143 
144 #if JLDEF_BUILD > JLL_ERROR
145 #define JOURNALEXCEPTIONS_BEGIN(journal) try {
146 #define JOURNALEXCEPTIONS_END_NOTHROW(journal) } catch(...) { }
147 #define JOURNALEXCEPTIONS_END_RETHROW(journal) } catch(...) { throw; }
148 #else
149 #define JOURNALEXCEPTIONS_BEGIN(journal) \
150  try {
151 
152 #define JOURNALEXCEPTIONS_END_NOTHROW(journal) \
153  } catch (JournalException& e) { JLERROR(journal, e.msg()); JLERROR_NODEC(journal, e.stack()); }\
154  catch (XsException& e) { JLERROR(journal, e.what()); }\
155  catch (std::exception& e) { JLERROR(journal, e.what()); }
156 
157 #define JOURNALEXCEPTIONS_END_RETHROW(journal) \
158  } catch (JournalException& e) { JLERROR(journal, e.msg()); JLERROR_NODEC(journal, e.stack()); throw; }\
159  catch (XsException& e) { JLERROR(journal, e.what()); throw; }\
160  catch (std::exception& e) { JLERROR(journal, e.what()); throw; }
161 #endif
162 
163 #endif
xsexception.h
JournalException::~JournalException
~JournalException()
Definition: journalexception.h:82
gOnExceptionGotoDebugger
bool gOnExceptionGotoDebugger
Definition: journalexception.cpp:121
JournalExceptionStackWalker
A helper class that combines the StackWalker output into a std::string.
Definition: journalexception.cpp:69
JournalException::JournalException
JournalException(std::string const &message)
Constructor, copies the message and creates a stack dump.
Definition: journalexception.cpp:91
journaller.h
Journaller
A journalling class for debugging applications.
Definition: journaller.h:79
JournalException
An exception class that automatically includes stack dump information.
Definition: journalexception.h:78
JournalException::stack
const std::string & stack() const
The stack dump as it was at the time of object construction.
Definition: journalexception.cpp:107
JournalException::msg
const char * msg() const
The message as supplied to the constructor.
Definition: journalexception.cpp:101
JournalException::m_stack
std::string m_stack
A string that contains a stack dump.
Definition: journalexception.h:88


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:20