ADTF  3.18.2
dd_error.h
Go to the documentation of this file.
1 
15 #ifndef DD_ERROR_H_INCLUDED
16 #define DD_ERROR_H_INCLUDED
17 
18 #include <stdexcept>
19 #include <vector>
20 
21 namespace ddl {
22 
23 namespace dd {
24 
29 struct Problem {
31  std::string item_name = {};
33  std::string problem_message = {};
34 };
35 
53 std::vector<std::string> transformProblemList(const std::vector<Problem>& problems);
54 
60 class Error : public std::exception {
61 private:
62  static std::string joinArgs(const std::vector<std::string>& oo_operation_args);
63 
64 public:
71  Error(const std::string& oo_type_operation, const std::string& message)
72  : _message(oo_type_operation + ": " + message)
73  {
74  _problems.push_back({oo_type_operation, message});
75  }
76 
84  Error(const std::string& oo_type_operation,
85  const std::vector<std::string>& oo_operation_args,
86  const std::string& message)
87  : _message(oo_type_operation + "(" + joinArgs(oo_operation_args) + ")" + ": " + message)
88  {
89  _problems.push_back({oo_type_operation + "(" + joinArgs(oo_operation_args) + ")", message});
90  }
91 
100  Error(const std::string& oo_type_operation,
101  const std::vector<std::string>& oo_operation_args,
102  const std::string& message,
103  const std::vector<Problem>& problems)
104  : _message(oo_type_operation + "(" + joinArgs(oo_operation_args) + ")" + ": " + message),
105  _problems(problems)
106  {
107  }
112  const std::vector<Problem>& problems() const
113  {
114  return _problems;
115  }
116 
121  char const* what() const noexcept override
122  {
123  return _message.c_str();
124  }
125 
126 private:
127  std::string _message;
128  std::vector<Problem> _problems;
129 };
130 
131 } // namespace dd
132 } // namespace ddl
133 
134 #endif // DD_ERROR_H_INCLUDED
Exception helper class to collect information while parsing, adding DD Objects or other failed operat...
Definition: dd_error.h:60
const std::vector< Problem > & problems() const
get the problems
Definition: dd_error.h:112
Error(const std::string &oo_type_operation, const std::string &message)
CTOR.
Definition: dd_error.h:71
Error(const std::string &oo_type_operation, const std::vector< std::string > &oo_operation_args, const std::string &message)
CTOR with arguments.
Definition: dd_error.h:84
Error(const std::string &oo_type_operation, const std::vector< std::string > &oo_operation_args, const std::string &message, const std::vector< Problem > &problems)
CTOR with arguments.
Definition: dd_error.h:100
char const * what() const noexcept override
get the problem message
Definition: dd_error.h:121
std::vector< std::string > transformProblemList(const std::vector< Problem > &problems)
transforms the Problem List to a simple vector of strings.
Problem to report to find the corresponding item name in a simple way.
Definition: dd_error.h:29
std::string problem_message
the validation problem in text
Definition: dd_error.h:33
std::string item_name
the item name
Definition: dd_error.h:31