Taskolib  1.3.3
exceptions.h
Go to the documentation of this file.
1 
23 // SPDX-License-Identifier: LGPL-2.1-or-later
24 
25 #ifndef TASKOLIB_EXCEPTIONS_H_
26 #define TASKOLIB_EXCEPTIONS_H_
27 
28 #include <cstring>
29 #include <stdexcept>
30 #include <string>
31 
32 #include "taskolib/StepIndex.h"
33 
34 namespace task {
35 
72 class Error : public std::runtime_error
73 {
74 public:
75  explicit Error(const std::string& msg, OptionalStepIndex opt_step_index = gul14::nullopt)
76  : std::runtime_error(msg)
77  , index_{ opt_step_index }
78  {}
79 
80  explicit Error(const char* msg, OptionalStepIndex opt_step_index = gul14::nullopt)
81  : std::runtime_error(msg)
82  , index_{ opt_step_index }
83  {}
84 
86  OptionalStepIndex get_index() const { return index_; }
87 
89  friend bool operator==(const Error& lhs, const Error& rhs) noexcept
90  {
91  return (std::strcmp(lhs.what(), rhs.what()) == 0)
92  && lhs.index_ == rhs.index_;
93  }
94 
96  friend bool operator!=(const Error& lhs, const Error& rhs) noexcept
97  {
98  return !(lhs == rhs);
99  }
100 
101 private:
103 };
104 
105 } // namespace task
106 
107 #endif
Declaration of the StepIndex type.
An exception class carrying an error message and, optionally, the index of the step in which the erro...
Definition: exceptions.h:73
OptionalStepIndex get_index() const
Return the associated step index.
Definition: exceptions.h:86
OptionalStepIndex index_
Definition: exceptions.h:102
friend bool operator==(const Error &lhs, const Error &rhs) noexcept
Determine if two Error objects have the same content.
Definition: exceptions.h:89
Error(const std::string &msg, OptionalStepIndex opt_step_index=gul14::nullopt)
Definition: exceptions.h:75
Error(const char *msg, OptionalStepIndex opt_step_index=gul14::nullopt)
Definition: exceptions.h:80
friend bool operator!=(const Error &lhs, const Error &rhs) noexcept
Determine if two Error objects have different content.
Definition: exceptions.h:96
Definition: VariableName.h:154
Namespace task contains all Taskolib functions and classes.
Definition: CommChannel.h:33
gul14::optional< StepIndex > OptionalStepIndex
An optional step index (gul14::optional<StepIndex>).
Definition: StepIndex.h:37