NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
system_exception.hpp
1#ifndef NEFORCE_CORE_EXCEPTION_SYSTEM_EXCEPTION_HPP__
2#define NEFORCE_CORE_EXCEPTION_SYSTEM_EXCEPTION_HPP__
5NEFORCE_BEGIN_NAMESPACE__
6
11
16struct system_exception : exception {
17 explicit system_exception(const char* info = "System Access Failed.", const error_code code = last_error()) noexcept
18 :
19 exception(info),
20 code_(code) {}
21
22 explicit system_exception(const error_code code) :
23 code_(code) {}
24
25 explicit system_exception(const exception& e) :
26 exception(e) {}
27
28 ~system_exception() override = default;
29
30 NEFORCE_NODISCARD const char* type() const noexcept override { return "system_exception"; }
31
32 NEFORCE_NODISCARD virtual const error_code& code() const noexcept { return code_; }
33
34protected:
35 error_code code_;
36};
37
42struct device_exception : system_exception {
43 explicit device_exception(const char* info = "Device Operation Failed.",
44 const error_code code = last_error()) noexcept :
45 system_exception(info, code) {}
46
47 explicit device_exception(const error_code err) :
48 system_exception(err) {}
49
50 explicit device_exception(const exception& e) :
51 system_exception(e) {}
52
53 ~device_exception() override = default;
54
55 NEFORCE_NODISCARD const char* type() const noexcept override { return "device_exception"; }
56};
57
62struct file_exception final : system_exception {
63 explicit file_exception(const char* info = "File Operation Failed.", const error_code code = last_error()) noexcept
64 :
65 system_exception(info, code) {}
66
67 explicit file_exception(const error_code err) :
68 system_exception(err) {}
69
70 explicit file_exception(const exception& e) :
71 system_exception(e) {}
72
73 ~file_exception() override = default;
74
75 NEFORCE_NODISCARD const char* type() const noexcept override { return "file_exception"; }
76};
77
82struct network_exception : system_exception {
83 explicit network_exception(const char* info = "Network Operation or Action Failed.",
84 const error_code code = last_error()) noexcept :
85 system_exception(info, code) {}
86
87 explicit network_exception(const error_code err) :
88 system_exception(err) {}
89
90 explicit network_exception(const exception& e) :
91 system_exception(e) {}
92
93 ~network_exception() override = default;
94
95 NEFORCE_NODISCARD const char* type() const noexcept override { return "network_exception"; }
96};
97 // Exceptions
99
100NEFORCE_END_NAMESPACE__
101#endif // NEFORCE_CORE_EXCEPTION_SYSTEM_EXCEPTION_HPP__
异常处理框架
error_code last_error() noexcept
获取当前系统错误码
const char * type() const noexcept override
获取异常类型
exception(const char *info="")
构造函数
const char * type() const noexcept override
获取异常类型
const char * type() const noexcept override
获取异常类型
const char * type() const noexcept override
获取异常类型