Error.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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
18class Error {
19public:
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
39extern const char *err_type_str[];
40
41inline
43errorTypeByName(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
51inline
52const char *
54{
55 if (err < ERR_NONE || err >= ERR_MAX)
56 return "UNKNOWN";
57 return err_type_str[err];
58}
59
60std::ostream &operator <<(std::ostream &os, const Error &error);
61
62#endif /* _SQUID_SRC_ERROR_ERROR_H */
63
std::ostream & operator<<(std::ostream &os, const Error &error)
Definition: Error.cc:32
err_type errorTypeByName(const char *name)
Definition: Error.h:43
const char * errorTypeName(err_type err)
Definition: Error.h:53
const char * err_type_str[]
Definition: stub_liberror.cc:8
void error(char *format,...)
a transaction problem
Definition: Error.h:18
err_type category
primary error classification (or ERR_NONE)
Definition: Error.h:35
Error(const err_type c)
support implicit conversions
Definition: Error.h:21
Error(const err_type c, const ErrorDetailPointer &d)
Definition: Error.h:22
void update(const err_type c, const ErrorDetailPointer &d)
convenience wrapper for update(Error)
Definition: Error.h:30
void update(const Error &)
if necessary, stores the given error information (if any)
Definition: Error.cc:16
ErrorDetailPointer detail
additional details about the error
Definition: Error.h:36
void clear()
switch to the default "no error information" state
Definition: Error.h:33
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