VLink
2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
exception.h
浏览该文件的文档.
1
/*
2
* Copyright (C) 2026 by Thun Lu. All rights reserved.
3
* Author: Thun Lu <thun.lu@zohomail.cn>
4
* Repo: https://github.com/thun-res/vlink
5
* _ __ __ _ __
6
* | | / / / / (_) ____ / /__
7
* | | / / / / / / / __ \ / //_/
8
* | |/ / / /___ / / / / / / / ,<
9
* |___/ /_____/ /_/ /_/ /_/ /_/|_|
10
*
11
* Licensed under the Apache License, Version 2.0 (the "License");
12
* you may not use this file except in compliance with the License.
13
* You may obtain a copy of the License at
14
*
15
* http://www.apache.org/licenses/LICENSE-2.0
16
*
17
* Unless required by applicable law or agreed to in writing, software
18
* distributed under the License is distributed on an "AS IS" BASIS,
19
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
* See the License for the specific language governing permissions and
21
* limitations under the License.
22
*/
23
24
/**
25
* @file exception.h
26
* @brief VLink-specific exception types wrapping the C++ standard exception hierarchy.
27
*
28
* @details
29
* All VLink exception classes are thin @c final wrappers that inherit their
30
* constructors from the corresponding standard exception base. They are grouped
31
* inside the @c vlink::Exception namespace to avoid naming conflicts with
32
* application code.
33
*
34
* The mapping between VLink exceptions and standard bases is:
35
*
36
* | VLink exception | Standard base | Typical usage |
37
* | ------------------------ | -------------------------- | ------------------------------------ |
38
* | Exception::RuntimeError | std::runtime_error | General runtime failures (fatal log) |
39
* | Exception::OutOfRange | std::out_of_range | Index or iterator out of valid range |
40
* | Exception::InvalidArgument | std::invalid_argument | Bad function argument |
41
* | Exception::LogicError | std::logic_error | Violated precondition |
42
* | Exception::DomainError | std::domain_error | Value outside the function domain |
43
* | Exception::LengthError | std::length_error | Size exceeds implementation limit |
44
* | Exception::RangeError | std::range_error | Arithmetic range error |
45
* | Exception::OverflowError | std::overflow_error | Arithmetic overflow |
46
* | Exception::UnderflowError| std::underflow_error | Arithmetic underflow |
47
*
48
* @note
49
* @c Exception::RuntimeError is the exception thrown by @c Logger when a
50
* @c kFatal-level log message is emitted. If a @c kFatal log occurs the
51
* Logger flushes all pending output and then throws this exception, allowing
52
* the application to catch it and perform a controlled shutdown.
53
*
54
* @par Example
55
* @code
56
* try {
57
* VLOG_F("Critical failure: ", reason);
58
* } catch (const vlink::Exception::RuntimeError& e) {
59
* // perform cleanup before process exit
60
* std::cerr << e.what() << "\n";
61
* }
62
* @endcode
63
*/
64
65
#pragma once
66
67
#include <stdexcept>
68
69
namespace
vlink
{
70
71
/**
72
* @namespace vlink::Exception
73
* @brief Container namespace for all VLink exception types.
74
*/
75
namespace
Exception
{
// NOLINT(readability-identifier-naming)
76
77
/**
78
* @class RuntimeError
79
* @brief Indicates a general runtime failure.
80
*
81
* @details
82
* Thrown by the Logger when a @c kFatal log level is used. Inherits all
83
* constructors from @c std::runtime_error so it can be constructed with
84
* an @c std::string or C-string message.
85
*/
86
class
RuntimeError
final :
public
std::runtime_error {
87
using
std::runtime_error::runtime_error;
88
};
89
90
/**
91
* @class OutOfRange
92
* @brief Indicates an index or iterator that is outside the valid range.
93
*
94
* @details
95
* Inherits all constructors from @c std::out_of_range.
96
*/
97
class
OutOfRange
final :
public
std::out_of_range {
98
using
std::out_of_range::out_of_range;
99
};
100
101
/**
102
* @class InvalidArgument
103
* @brief Indicates that a function received an argument with an invalid value.
104
*
105
* @details
106
* Inherits all constructors from @c std::invalid_argument.
107
*/
108
class
InvalidArgument
final :
public
std::invalid_argument {
109
using
std::invalid_argument::invalid_argument;
110
};
111
112
/**
113
* @class LogicError
114
* @brief Indicates a violated program logic precondition.
115
*
116
* @details
117
* Inherits all constructors from @c std::logic_error.
118
*/
119
class
LogicError
final :
public
std::logic_error {
120
using
std::logic_error::logic_error;
121
};
122
123
/**
124
* @class DomainError
125
* @brief Indicates that a value is outside the domain of a mathematical function.
126
*
127
* @details
128
* Inherits all constructors from @c std::domain_error.
129
*/
130
class
DomainError
final :
public
std::domain_error {
131
using
std::domain_error::domain_error;
132
};
133
134
/**
135
* @class LengthError
136
* @brief Indicates an attempt to exceed the maximum allowable size or length.
137
*
138
* @details
139
* Inherits all constructors from @c std::length_error.
140
*/
141
class
LengthError
final :
public
std::length_error {
142
using
std::length_error::length_error;
143
};
144
145
/**
146
* @class RangeError
147
* @brief Indicates an arithmetic range error.
148
*
149
* @details
150
* Inherits all constructors from @c std::range_error.
151
*/
152
class
RangeError
final :
public
std::range_error {
153
using
std::range_error::range_error;
154
};
155
156
/**
157
* @class OverflowError
158
* @brief Indicates an arithmetic overflow.
159
*
160
* @details
161
* Inherits all constructors from @c std::overflow_error.
162
*/
163
class
OverflowError
final :
public
std::overflow_error {
164
using
std::overflow_error::overflow_error;
165
};
166
167
/**
168
* @class UnderflowError
169
* @brief Indicates an arithmetic underflow.
170
*
171
* @details
172
* Inherits all constructors from @c std::underflow_error.
173
*/
174
class
UnderflowError
final :
public
std::underflow_error {
175
using
std::underflow_error::underflow_error;
176
};
177
178
}
// namespace Exception
179
180
}
// namespace vlink
vlink::Exception::DomainError
Indicates that a value is outside the domain of a mathematical function.
定义
exception.h:130
vlink::Exception::InvalidArgument
Indicates that a function received an argument with an invalid value.
定义
exception.h:108
vlink::Exception::LengthError
Indicates an attempt to exceed the maximum allowable size or length.
定义
exception.h:141
vlink::Exception::LogicError
Indicates a violated program logic precondition.
定义
exception.h:119
vlink::Exception::OutOfRange
Indicates an index or iterator that is outside the valid range.
定义
exception.h:97
vlink::Exception::OverflowError
Indicates an arithmetic overflow.
定义
exception.h:163
vlink::Exception::RangeError
Indicates an arithmetic range error.
定义
exception.h:152
vlink::Exception::RuntimeError
Indicates a general runtime failure.
定义
exception.h:86
vlink::Exception::UnderflowError
Indicates an arithmetic underflow.
定义
exception.h:174
vlink::Exception
Container namespace for all VLink exception types.
vlink
定义
bytes.h:103
include
vlink
base
exception.h
制作者
1.16.1