|
|
| ErrorCollector (ErrorCollector &&)=default |
| |
|
ErrorCollector & | operator= (ErrorCollector &&)=default |
| |
|
| ErrorCollector (const ErrorCollector &)=default |
| |
|
ErrorCollector & | operator= (const ErrorCollector &)=default |
| |
| template<typename... Args> |
| auto & | AddError (this auto &self, ErrorKind kind, const std::format_string< Args... > fmt, Args &&... args) |
| | Add a specific error and return reference to derived class.
|
| |
| auto & | AddError (this auto &self, Error err) |
| | Add an existing error object and return reference to derived class.
|
| |
| auto & | AddError (this auto &self, std::unexpected< Error > err) |
| | Add an unexpected result's error and return reference to derived class.
|
| |
| bool | has_errors () const |
| | Check if any errors have been collected.
|
| |
| size_t | error_count () const |
| | Get the number of errors collected.
|
| |
| Status | CheckErrors () const |
| | Check for accumulated errors and return them if any exist.
|
| |
| void | ClearErrors () |
| | Clear all accumulated errors.
|
| |
|
const std::vector< Error > & | errors () const |
| | Get read-only access to all collected errors.
|
| |
Base class for collecting errors in the builder pattern.
This class equips builders with error accumulation capabilities to make it easy for method chaining. Builder methods should call AddError() to accumulate errors and call CheckErrors() before completing the build process.
Example usage:
public:
MyBuilder& SetValue(int val) {
if (val < 0) {
return AddError(ErrorKind::kInvalidArgument, "Value must be non-negative");
}
value_ = val;
return *this;
}
Result<MyObject> Build() {
ICEBERG_RETURN_UNEXPECTED(CheckErrors());
return MyObject{value_};
}
private:
int value_ = 0;
};
Base class for collecting errors in the builder pattern.
Definition error_collector.h:93