Error.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_SRC_ERROR_ERROR_H
10 #define SQUID_SRC_ERROR_ERROR_H
11 
12 #include "error/Detail.h"
13 #include "error/forward.h"
14 #include "mem/PoolingAllocator.h"
15 
16 #include <iosfwd>
17 #include <vector>
18 
20 using ErrorDetails = std::vector<ErrorDetailPointer, PoolingAllocator<ErrorDetailPointer> >;
21 
24 std::ostream &operator <<(std::ostream &, const ErrorDetails &);
25 
27 class Error {
28 public:
29  Error() = default;
30  Error(const err_type c): category(c) {}
31  Error(const err_type c, const ErrorDetailPointer &d): Error(c) { update(d); }
32 
33  explicit operator bool() const { return category != ERR_NONE; }
34 
36  void update(const Error &);
37 
40  void update(err_type, const ErrorDetailPointer &);
41 
45  void update(err_type);
46 
50  void update(const ErrorDetailPointer &detail);
51 
53  void clear() { *this = Error(); }
54 
56 
61 };
62 
63 extern const char *err_type_str[];
64 
65 inline
67 errorTypeByName(const char *name)
68 {
69  for (int i = 0; i < ERR_MAX; ++i)
70  if (strcmp(name, err_type_str[i]) == 0)
71  return (err_type)i;
72  return ERR_MAX;
73 }
74 
75 inline
76 const char *
78 {
79  if (err < ERR_NONE || err >= ERR_MAX)
80  return "UNKNOWN";
81  return err_type_str[err];
82 }
83 
84 std::ostream &operator <<(std::ostream &os, const Error &error);
85 
86 #endif /* SQUID_SRC_ERROR_ERROR_H */
87 
void error(char *format,...)
const char * err_type_str[]
@ ERR_NONE
Definition: forward.h:15
err_type
Definition: forward.h:14
a transaction problem
Definition: Error.h:27
const char * errorTypeName(err_type err)
Definition: Error.h:77
ErrorDetails details
Definition: Error.h:60
err_type errorTypeByName(const char *name)
Definition: Error.h:67
std::vector< ErrorDetailPointer, PoolingAllocator< ErrorDetailPointer > > ErrorDetails
zero or more details of a single error
Definition: Error.h:20
@ ERR_MAX
Definition: forward.h:88
Error(const err_type c, const ErrorDetailPointer &d)
Definition: Error.h:31
Error()=default
void update(const Error &)
if necessary, stores the given error information (if any)
Definition: Error.cc:51
err_type category
primary error classification (or ERR_NONE)
Definition: Error.h:55
std::ostream & operator<<(std::ostream &, const ErrorDetails &)
Definition: Error.cc:70
void clear()
switch to the default "no error information" state
Definition: Error.h:53

 

Introduction

Documentation

Support

Miscellaneous