HEBench
error_handling.hpp
Go to the documentation of this file.
1 
2 // Copyright (C) 2021 Intel Corporation
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef _HEBench_API_Bridge_Error_H_7e5fa8c2415240ea93eff148ed73539b
6 #define _HEBench_API_Bridge_Error_H_7e5fa8c2415240ea93eff148ed73539b
7 
8 #include <stdexcept>
9 #include <string>
10 
11 namespace hebench {
12 namespace cpp {
13 
14 #define HEBERROR_DECLARE_CLASS_NAME(class_name) static constexpr const char *m_private_class_name = #class_name;
15 
16 #define HEBERROR_MSG_CLASS(message) hebench::cpp::HEBenchError::generateMessage((message), \
17  __func__, m_private_class_name, \
18  __FILE__, __LINE__)
19 
20 #define HEBERROR_MSG(message) hebench::cpp::HEBenchError::generateMessage((message), \
21  __func__, std::string(), \
22  __FILE__, __LINE__)
23 
24 class HEBenchError : public std::runtime_error
25 {
26 public:
27  HEBenchError(const std::string &msg = std::string(), int err_code = 0) :
28  std::runtime_error(msg), m_err_code(err_code)
29  {
30  }
31 
32  int getErrorCode() const { return m_err_code; }
33 
34  static std::string generateMessage(const std::string &message,
35  const std::string &function,
36  const std::string &container,
37  const std::string &filename,
38  int line_no);
39 
40 private:
41  int m_err_code;
42 };
43 
44 } // namespace cpp
45 } // namespace hebench
46 
47 #endif // defined _HEBench_API_Bridge_Error_H_7e5fa8c2415240ea93eff148ed73539b
static std::string generateMessage(const std::string &message, const std::string &function, const std::string &container, const std::string &filename, int line_no)
HEBenchError(const std::string &msg=std::string(), int err_code=0)