YSTest: exception.h 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

ystdex/exception.h
浏览该文件的文档.
1 /*
2 © 2014-2016 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YB_INC_ystdex_exception_hpp_
29 #define YB_INC_ystdex_exception_hpp_ 1
30
31 #include <libdefect/exception.h> // for std::exception_ptr,
32 // std::nested_exception;
33 #include "deref_op.hpp" // for call_value_or;
34 #include <functional> // for std::mem_fn;
35 #include <memory> // for std::addressof;
36 #include "type_traits.hpp" // for remove_cv_t;
37 #include <stdexcept> // for std::logic_error;
38 #include <system_error> // for std::error_category, std::generic_category,
39 // std::system_error, std::errc;
40
41 namespace ystdex
42 {
43
54 template<typename _func>
55 void
56 iterate_exceptions(_func&& f, std::exception_ptr p = std::current_exception())
57 {
58 while(p)
59 p = yforward(f)(p);
60 }
61
67 template<class _tEx>
68 inline std::exception_ptr
69 get_nested_exception_ptr(const _tEx& e)
70 {
71 return ystdex::call_value_or<std::exception_ptr>(
72 std::mem_fn(&std::nested_exception::nested_ptr),
73 dynamic_cast<const std::nested_exception*>(std::addressof(e)));
74 }
75
80 template<typename _type>
81 YB_NORETURN inline void
82 raise_exception(_type&& e)
83 {
84 if(std::current_exception())
85 std::throw_with_nested(yforward(e));
86 throw yforward(e);
87 }
88
89
94 template<typename _tEx, typename _func,
95 typename _tExCaught = remove_cv_t<_tEx>&>
96 void
97 handle_nested(_tEx& e, _func&& f)
98 {
99 try
100 {
101 std::rethrow_if_nested(e);
102 }
103 catch(_tExCaught ex)
104 {
105 yforward(f)(ex);
106 }
107 }
108
109
115 class YB_API unsupported : public std::logic_error
117 {
118 public:
119 unsupported()
120 : logic_error("Unsupported operation found.")
121 {}
123 using logic_error::logic_error;
125 unsupported(const unsupported&) = default;
130 ~unsupported() override;
131 };
132
133
135 class YB_API unimplemented : public unsupported
136 {
137 public:
138 unimplemented()
139 : unsupported("Unimplemented operation found.")
140 {}
142 using unsupported::unsupported;
144 unimplemented(const unimplemented&) = default;
149 ~unimplemented() override;
150 };
152
153
160 template<class _type = std::system_error, typename... _tParams>
161 YB_NORETURN inline void
162 throw_error(std::error_code ec, _tParams&&... args)
163 {
164 throw _type(ec, yforward(args)...);
165 }
166 template<class _type = std::system_error, typename... _tParams>
167 YB_NORETURN inline void
168 throw_error(std::error_condition cond, _tParams&&... args)
169 {
170 throw _type(cond.value(), cond.category(), yforward(args)...);
171 }
172 template<class _type = std::system_error, typename... _tParams>
173 YB_NORETURN inline void
174 throw_error(int ev, _tParams&&... args)
175 {
176 throw _type(ev, std::generic_category(), yforward(args)...);
177 }
178 template<class _type = std::system_error, typename... _tParams>
179 YB_NORETURN inline void
180 throw_error(int ev, const std::error_category& ecat, _tParams&&... args)
181 {
182 throw _type(ev, ecat, yforward(args)...);
183 }
185
186 } // namespace ystdex;
187
188 #endif
189
platform::p
while p p
Definition: YCLib/FileSystem.h:225
YB_NORETURN
#define YB_NORETURN
指定无返回值函数。
Definition: ydef.h:478
exception.h
deref_op.hpp
解引用操作。
CHRLib::e
const char const char * e
Definition: CharacterProcessing.h:109
ystdex::unimplemented::unimplemented
unimplemented()
Definition: ystdex/exception.h:138
YB_API
#define YB_API
YBase 应用程序编程接口：用于向库文件约定链接。
Definition: ydef.h:566
ystdex::handle_nested
void handle_nested(_tEx &e, _func &&f)
处理嵌套异常。
Definition: ystdex/exception.h:97
ystdex::throw_error
void throw_error(std::error_code ec, _tParams &&...args)
抛出错误： std::system_error 或允许相同构造函数参数的异常。
Definition: ystdex/exception.h:162
ystdex
特性测试宏。
Definition: ydef.h:796
type_traits.hpp
ISO C++ 类型特征扩展。
ystdex::iterate_exceptions
void iterate_exceptions(_func &&f, std::exception_ptr p=std::current_exception())
迭代处理异常。
Definition: ystdex/exception.h:56
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:969
YSLib::IO::f
const string &path const String &path _func f
Definition: YSLib/Service/FileSystem.h:430
CHRLib::args
_tParams && args
Definition: CharacterProcessing.h:538
ystdex::get_nested_exception_ptr
std::exception_ptr get_nested_exception_ptr(const _tEx &e)
取嵌套异常指针。
Definition: ystdex/exception.h:69
ystdex::raise_exception
void raise_exception(_type &&e)
引发异常：若当前存在正在处理的异常则抛出嵌套异常，否则抛出异常。
Definition: ystdex/exception.h:82
ystdex::unsupported
异常：不支持的操作。
Definition: ystdex/exception.h:116
ystdex::unimplemented
异常：未实现的操作。
Definition: ystdex/exception.h:135
ystdex::unsupported::unsupported
unsupported()
Definition: ystdex/exception.h:119