RmsRuntimeException.h
Go to the documentation of this file.
1 #ifndef _RMS_RUNTIMEEXCEPTION_H
2 #define _RMS_RUNTIMEEXCEPTION_H
3 
4 #include <execinfo.h>
5 #include <stdexcept>
6 #include <string>
7 #include <sstream>
8 
9 #define GENERATE_RMS_RUNTIME_EXCEPTION(msg) \
10  throw gov::fnal::cd::rms::base::RmsRuntimeException(__FILE__, __LINE__, msg)
11 
12 #define GENERATE_RMS_NOTCONNECTED_EXCEPTION(msg) \
13 throw gov::fnal::cd::rms::base::RmsNotConnectedException(__FILE__, __LINE__, msg)
14 
15 #define GENERATE_RMS_EXITINGPROCESS_EXCEPTION(msg) \
16 throw gov::fnal::cd::rms::base::RmsExitingProcessException(__FILE__, __LINE__, msg)
17 
18 #if CETDDS_DEBUG
19 #define LOG_EXCEPTION(message,what) std::cerr << message << what << std::endl
20 #else
21 #define LOG_EXCEPTION(message,what)
22 #endif
23 
24 namespace gov {
25 
26 namespace fnal {
27 
28 namespace cd {
29 
30 namespace rms {
31 
32 namespace base {
33 
34 /**
35  * Class to report runtime exceptions.
36  *
37  * @author Kurt Biery
38  * @author Steve Foulkes
39  * @version $Revision: 1.2.14.1 $ $Date: 2019/09/27 00:07:31 $
40  */
41 
43 
44  public:
45 
46  /**
47  * Constructs a runtime exception instance from the specified
48  * file, line number, and message.
49  */
51  const std::string &message) {
52 
53  // convert the line number to a string
54  std::stringstream tmpStream;
55  tmpStream << line;
56  std::string lineNumber = tmpStream.str();
57 
58  // build up the exception text
59  _fullText = message + "\n" + " RmsRuntimeException generated at " +
60  fileName + ":" + lineNumber;
61 
62  // add some limited stack trace information
63  void *array[10];
64  size_t size;
65  char **strings;
66  size_t idx;
67 
68  size = backtrace (array, 10);
69  strings = backtrace_symbols (array, size);
70  tmpStream.seekp(0); // clear out the stream
71  for (idx = 0; idx < size; idx++) {
72  tmpStream << " " << strings[idx] << std::endl;
73  }
74  free (strings);
75 
76  _fullText += "\n Stack trace:\n" + tmpStream.str();
77  }
78 
79  /**
80  * Destructor.
81  */
82  virtual ~RmsRuntimeException() throw() {
83  return;
84  }
85 
86  /**
87  * Returns a description of the exception.
88  */
89  const char* what() const throw() {
90  return _fullText.c_str();
91  }
92 
93  private:
94 
95  /**
96  * The full description of the exception.
97  */
99 
100 };
101 
103 {
104 public:
106  :RmsRuntimeException(fileName,line,message) {};
107 };
108 
110 {
111 public:
113  :RmsRuntimeException(fileName,line,message) {};
114 };
115 
116 } // end of namespace base
117 
118 } // end of namespace rms
119 
120 } // end of namespace cd
121 
122 } // end of namespace fnal
123 
124 } // end of namespace gov
125 
126 #endif
127 
fileName
Definition: plotROC.py:78
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
RmsExitingProcessException(const std::string &fileName, int line, const std::string &message)
const XML_Char int const XML_Char int const XML_Char * base
Definition: expat.h:331
RmsRuntimeException(const std::string &fileName, int line, const std::string &message)
Definition: fnal.py:1
RmsNotConnectedException(const std::string &fileName, int line, const std::string &message)
c cd(1)
enum BeamMode string