Error.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 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 
15 #include <iosfwd>
16 
18 class Error {
19 public:
20  Error() = default;
21  Error(const err_type c): category(c) {}
22  Error(const err_type c, const ErrorDetailPointer &d): category(c), detail(d) {}
23 
24  explicit operator bool() const { return category != ERR_NONE; }
25 
27  void update(const Error &);
28 
30  void update(const err_type c, const ErrorDetailPointer &d) { update(Error(c, d)); }
31 
33  void clear() { *this = Error(); }
34 
37 };
38 
39 extern const char *err_type_str[];
40 
41 inline
43 errorTypeByName(const char *name)
44 {
45  for (int i = 0; i < ERR_MAX; ++i)
46  if (strcmp(name, err_type_str[i]) == 0)
47  return (err_type)i;
48  return ERR_MAX;
49 }
50 
51 inline
52 const char *
54 {
55  if (err < ERR_NONE || err >= ERR_MAX)
56  return "UNKNOWN";
57  return err_type_str[err];
58 }
59 
60 std::ostream &operator <<(std::ostream &os, const Error &error);
61 
62 #endif /* _SQUID_SRC_ERROR_ERROR_H */
63 
ErrorDetailPointer detail
additional details about the error
Definition: Error.h:36
Error(const err_type c)
support implicit conversions
Definition: Error.h:21
void error(char *format,...)
const char * err_type_str[]
Definition: stub_liberror.cc:8
@ ERR_NONE
Definition: forward.h:15
err_type
Definition: forward.h:14
a transaction problem
Definition: Error.h:18
const char * errorTypeName(err_type err)
Definition: Error.h:53
void update(const err_type c, const ErrorDetailPointer &d)
convenience wrapper for update(Error)
Definition: Error.h:30
err_type errorTypeByName(const char *name)
Definition: Error.h:43
@ ERR_MAX
Definition: forward.h:88
std::ostream & operator<<(std::ostream &os, const Error &error)
Definition: Error.cc:32
Error(const err_type c, const ErrorDetailPointer &d)
Definition: Error.h:22
Error()=default
void update(const Error &)
if necessary, stores the given error information (if any)
Definition: Error.cc:16
err_type category
primary error classification (or ERR_NONE)
Definition: Error.h:35
void clear()
switch to the default "no error information" state
Definition: Error.h:33

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors