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"
15
16#include <iosfwd>
17#include <vector>
18
20using ErrorDetails = std::vector<ErrorDetailPointer, PoolingAllocator<ErrorDetailPointer> >;
21
24std::ostream &operator <<(std::ostream &, const ErrorDetails &);
25
27class Error {
28public:
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
63extern const char *err_type_str[];
64
65inline
67errorTypeByName(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
75inline
76const char *
78{
79 if (err < ERR_NONE || err >= ERR_MAX)
80 return "UNKNOWN";
81 return err_type_str[err];
82}
83
84std::ostream &operator <<(std::ostream &os, const Error &error);
85
86#endif /* _SQUID_SRC_ERROR_ERROR_H */
87
std::ostream & operator<<(std::ostream &, const ErrorDetails &)
Definition: Error.cc:70
std::vector< ErrorDetailPointer, PoolingAllocator< ErrorDetailPointer > > ErrorDetails
zero or more details of a single error
Definition: Error.h:20
err_type errorTypeByName(const char *name)
Definition: Error.h:67
const char * errorTypeName(err_type err)
Definition: Error.h:77
const char * err_type_str[]
void error(char *format,...)
a transaction problem
Definition: Error.h:27
ErrorDetails details
Definition: Error.h:60
err_type category
primary error classification (or ERR_NONE)
Definition: Error.h:55
Error(const err_type c)
support implicit conversions
Definition: Error.h:30
Error(const err_type c, const ErrorDetailPointer &d)
Definition: Error.h:31
void update(const Error &)
if necessary, stores the given error information (if any)
Definition: Error.cc:51
void clear()
switch to the default "no error information" state
Definition: Error.h:53
Error()=default
err_type
Definition: forward.h:14
@ ERR_MAX
Definition: forward.h:88
@ ERR_NONE
Definition: forward.h:15

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors