LDMX Software
Exception.h
1#ifndef FRAMEWORK_EXCEPTION_H
2#define FRAMEWORK_EXCEPTION_H
3
4/*~~~~~~~~~~~~~~~~*/
5/* C++ StdLib */
6/*~~~~~~~~~~~~~~~~*/
7#include <exception>
8#include <string>
9
10namespace framework {
11namespace exception {
12
20class Exception : public std::exception {
21 public:
27 Exception() throw() {}
28
37 Exception(const std::string &name, const std::string &message,
38 const std::string &module, int line, const std::string &function)
39 : name_{name},
43 line_{line} {
44 buildStackTrace();
45 }
46
50 virtual ~Exception() throw() {}
51
56 const std::string &name() const throw() { return name_; }
57
62 const std::string &message() const throw() { return message_; }
63
68 const std::string &module() const throw() { return module_; }
69
74 const std::string &function() const throw() { return function_; }
75
80 int line() const throw() { return line_; }
81
86 virtual const char *what() const throw() { return message_.c_str(); }
87
91 const std::string &stackTrace() const throw() { return stackTrace_; }
92
93 private:
94 void buildStackTrace() throw();
95
97 std::string name_;
98
100 std::string message_;
101
103 std::string module_;
104
106 std::string function_;
107
109 int line_{0};
110
112 std::string stackTrace_;
113};
114} // namespace exception
115} // namespace framework
116
126#define EXCEPTION_RAISE(EXCEPTION, MSG) \
127 throw framework::exception::Exception(EXCEPTION, MSG, __FILE__, __LINE__, \
128 __FUNCTION__)
129#endif
Standard base exception class with some useful output information.
Definition Exception.h:20
Exception(const std::string &name, const std::string &message, const std::string &module, int line, const std::string &function)
Class constructor.
Definition Exception.h:37
Exception()
Empty constructor.
Definition Exception.h:27
const std::string & function() const
Get the function name where the exception occurred.
Definition Exception.h:74
int line() const
Get the source line number where the exception occurred.
Definition Exception.h:80
virtual const char * what() const
The error message.
Definition Exception.h:86
const std::string & message() const
Get the message of the exception.
Definition Exception.h:62
virtual ~Exception()
Class destructor.
Definition Exception.h:50
std::string function_
Function name where the exception occurred.
Definition Exception.h:106
std::string stackTrace_
The stack trace.
Definition Exception.h:112
int line_
Source line number where the exception occurred.
Definition Exception.h:109
const std::string & name() const
Get the name of the exception.
Definition Exception.h:56
std::string module_
Source filename where the exception occurred.
Definition Exception.h:103
const std::string & stackTrace() const
Get the full stack trace.
Definition Exception.h:91
std::string message_
Error message.
Definition Exception.h:100
const std::string & module() const
Get the source filename where the exception occurred.
Definition Exception.h:68
std::string name_
Exception name.
Definition Exception.h:97
All classes in the ldmx-sw project use this namespace.
Definition PerfDict.cxx:45