DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ExceptionBase.hh
Go to the documentation of this file.
1#ifndef __EXCEPTIONBASE_HPP__
2#define __EXCEPTIONBASE_HPP__ 1
3
4#include <exception> //for inheritance from std::exception
5
6#include <string.h> //for memcpy, strlen.
7
8#include <string> //std::string
9
10#include <stdlib.h> // for malloc
11
12#include <stdio.h>
13
14//For SYS_gettid()
15//#define _GNU_SOURCE /* See feature_test_macros(7) */
16#include <unistd.h>
17#include <sys/syscall.h> /* For SYS_xxx definitions */
18
19//Backtrace code
20#include <execinfo.h>
21
22//abi demangling
23#include <cxxabi.h>
24
25namespace BUException{
26
27 //Macro for derived exception classes
28#define ExceptionClassGenerator( ClassName , ClassDescription ) \
29 class ClassName : public BUException::exBase { \
30 public: \
31 ClassName() throw() {Init();} \
32 ClassName(const ClassName & rh) throw() : \
33 BUException::exBase(rh) {Init();Copy(rh);} \
34 ClassName & operator=(const ClassName & rh) throw() \
35 {Init();Copy(rh);return *this;} \
36 ~ClassName() throw() {} \
37 const char * what() const throw() {return whatname;} \
38 private: \
39 void Init() \
40 { \
41 strcpy(whatname,ClassDescription); \
42 } \
43 char whatname[sizeof(ClassDescription)]; \
44 };
45
46
47 class exBase : public std::exception {
48 public:
49 //destructor
50 virtual ~exBase() throw();
51
52 //Returns a stack trace of where the exception happened
53 const char * StackTrace() const throw();
54
55 //Append info to the description message
56 void Append(const char * buffer) throw();
57 void Append(std::string str){Append(str.c_str());};
58 const char * Description() const throw();
59
60 //Return the what string
61 virtual const char * what() const throw() = 0;
62
63
64 pid_t GetPID(){return PID;};
65
66 protected:
67 //Constructor is protected so only derived classes can call it
68 exBase() throw() ;
69 //Copy function for base class internals (called by derived)
70 void Copy(const exBase & rh) throw();
71 exBase(const exBase & rh) throw() {(void) rh;}; // have to cast to void to keep from unused param error
72
73 private:
74 //assignment operator is private and not implemented
75 exBase & operator=(const exBase & rh) throw();
76
77 //Stack trace code
78 void GenerateStackTrace() throw();
79 void AppendStackLine(const char * line) throw(); //adds a eol char if possible
80
81 //Description internals
85
86 //Stack trace internals
87 size_t stackSize;
88 size_t stackUsed;
90
91 pid_t PID;
92 };
93}
94
95
96
97
98#endif
void Append(const char *buffer)
void AppendStackLine(const char *line)
const char * StackTrace() const
virtual const char * what() const =0
const char * Description() const
void Append(std::string str)
exBase & operator=(const exBase &rh)
void Copy(const exBase &rh)