33 #ifndef EPICSEXCEPTION_H_
34 #define EPICSEXCEPTION_H_
44 # define EXCEPT_DEPTH 20
47 #if defined(__GLIBC__) || (defined(__APPLE__) && defined(__MACH__))
48 # include <execinfo.h>
50 # define EXCEPT_USE_BACKTRACE
51 #elif defined(_WIN32) && !defined(_MINGW) && !defined(SKIP_DBGHELP)
55 # define EXCEPT_USE_CAPTURE
57 # define EXCEPT_USE_NONE
60 #if defined(_WIN32) && !defined(_MINGW)
61 #pragma warning( push )
62 #pragma warning(disable: 4275) // non dll-interface class used as base for dll-interface class (std::logic_error)
63 #pragma warning(disable: 4251) // class std::string needs to have dll-interface to be used by clients
66 namespace epics {
namespace pvData {
75 #ifndef EXCEPT_USE_NONE
76 void *m_stack[EXCEPT_DEPTH];
84 #if defined(EXCEPT_USE_BACKTRACE)
86 m_depth=backtrace(m_stack,EXCEPT_DEPTH);
88 #elif defined(EXCEPT_USE_CAPTURE)
90 m_depth=CaptureStackBackTrace(0,EXCEPT_DEPTH,m_stack,0);
96 void print(FILE *fp=stderr)
const;
101 #ifndef THROW_EXCEPTION_COMPAT
122 template<
typename A1>
127 template<
typename A1,
typename A2>
137 makeException(
const E&
self,
const char* file,
int line)
145 showException(
const E& ex)
155 #define THROW_EXCEPTION(E) \
157 throw ::epics::pvData::detail::makeException(E, __FILE__, __LINE__); \
161 #define THROW_EXCEPTION1(TYPE) \
163 throw ::epics::pvData::detail::ExceptionMixed<TYPE>(__FILE__, __LINE__); \
167 #define THROW_EXCEPTION2(TYPE,MSG) \
169 throw ::epics::pvData::detail::ExceptionMixed<TYPE>(MSG, __FILE__, __LINE__); \
172 #define PRINT_EXCEPTION2(EI, FP) \
174 ::epics::pvData::ExceptionMixin *_em_p=dynamic_cast< ::epics::pvData::ExceptionMixin*>(&EI); \
175 if (_em_p) {_em_p->print(FP);} \
178 #define PRINT_EXCEPTION(EI) PRINT_EXCEPTION2(EI,stderr)
180 #if !defined(__GNUC__) || __GNUC__ < 4
181 # define SHOW_EXCEPTION(EI) ::epics::pvData::detail::showException(EI)
183 # define SHOW_EXCEPTION(EI) \
184 ({ ::epics::pvData::ExceptionMixin *_mx=dynamic_cast< ::epics::pvData::ExceptionMixin*>(&(EI)); \
185 _mx ? _mx->show() : std::string(); \
189 #else // THROW_EXCEPTION_COMPAT
192 #define PRINT_EXCEPTION(EI) do{}while(0)
193 #define PRINT_EXCEPTION2(EI,FP) do{}while(0)
194 #define SHOW_EXCEPTION(EI) std::string()
196 #define THROW_EXCEPTION(E) do{throw (E);}while(0)
197 #define THROW_EXCEPTION1(E) do{throw (E)();}while(0)
198 #define THROW_EXCEPTION2(E,A) do{throw (E)(A);}while(0)
200 #endif // THROW_EXCEPTION_COMPAT
221 virtual const char* what()
const throw();
224 mutable std::
string base_msg;
227 #if defined(_WIN32) && !defined(_MINGW)
228 #pragma warning( pop )
231 #define THROW_BASE_EXCEPTION(msg) THROW_EXCEPTION2(::epics::pvData::BaseException, msg)
Base for pvData exceptions.
basic_string< char > string
BaseException(const std::string &msg)