YSTest: YException.h 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

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

- 文件列表
- 文件成员

YException.h
浏览该文件的文档.
1 /*
2 © 2010-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 YSL_INC_Core_yexcept_h_
29 #define YSL_INC_Core_yexcept_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YShellDefinition
33 #include <exception> // for mandated header;
34 #include <stdexcept> // for mandated header;
35 #include YFM_YSLib_Adaptor_YTextBase // for string_view;
36 #include <string> // for std::string;
37 #include <ystdex/functional.hpp> // for ystdex::non_void_result_t,
38 // ystdex::result_of_t, ystdex::invoke_nonvoid;
39
40 namespace YSLib
41 {
42
44
45 using GeneralEvent = std::runtime_error;
47
48
50 class YF_API LoggedEvent : public GeneralEvent
51 {
52 private:
54 RecordLevel level;
55
56 public:
62 YB_NONNULL(2)
64 LoggedEvent(const char* = "", RecordLevel = Emergent);
65 LoggedEvent(const string_view, RecordLevel = Emergent);
67
71 LoggedEvent(const GeneralEvent&, RecordLevel = Emergent);
73 DefDeCopyCtor(LoggedEvent)
78 ~LoggedEvent() override;
79
81 DefGetter(const ynothrow, RecordLevel, Level, level)
82 };
83
84
90 class YF_API FatalError : public GeneralEvent
91 {
92 private:
98 shared_ptr<string> content;
99
100 public:
107 YB_NONNULL(2)
108 FatalError(const char*, string_view);
110 DefDeCopyCtor(FatalError)
115 ~FatalError() override;
116
118 DefGetter(const ynothrow, string_view, Content, Deref(content))
119 DefGetter(const ynothrow, const char*, Title, what())
120 };
122
123
125
126
130 using ExtractedLevelPrinter
131 = std::function<void(const char*, RecordLevel, size_t)>;
132 template<typename _type>
133 using GLevelTracer = std::function<void(_type, RecordLevel)>;
134 using ExceptionTracer = GLevelTracer<const std::exception&>;
135
136
141 YF_API YB_NONNULL(1) void
142 TraceException(const char*, RecordLevel = Err, size_t level = 0) ynothrow;
143
149 YF_API void
150 TraceExceptionType(const std::exception&, RecordLevel = Err) ynothrow;
151
159 YF_API void
160 ExtractAndTrace(const std::exception&, RecordLevel = Err) ynothrow;
161
163 YF_API void
164 ExtractException(const ExtractedLevelPrinter&,
165 const std::exception&, RecordLevel = Err, size_t = 0) ynothrow;
167
169
170
176 YF_API bool
177 TryExecute(std::function<void()>, const char* = {}, RecordLevel = Alert,
178 ExceptionTracer = ExtractAndTrace);
179
184 template<typename _fCallable, typename... _tParams>
185 ystdex::nonvoid_result_t<ystdex::result_of_t<_fCallable&&(_tParams&&...)>>
186 TryInvoke(_fCallable&& f, _tParams&&... args) ynothrow
187 {
188 TryRet(ystdex::invoke_nonvoid(yforward(f), yforward(args)...))
189 CatchExpr(std::exception& e, ExtractAndTrace(e))
190 CatchExpr(..., YF_TraceRaw(Emergent, "Unknown exception found."))
191 return {};
192 }
193
201 template<typename _func>
202 bool
203 FilterExceptions(_func f, const char* desc = {}, RecordLevel lv = Alert,
204 ExceptionTracer trace = ExtractAndTrace) ynothrow
205 {
206 return !TryInvoke([=]{
207 return !TryExecute(f, desc, lv, trace);
208 });
209 }
211
212 } // namespace YSLib;
213
214 #endif
215
YSLib::TraceExceptionType
YF_API void TraceExceptionType(const std::exception &, RecordLevel=Err) ynothrow
通过 YF_TraceRaw 跟踪记录异常类型。
YSLib::FatalError::content
shared_ptr< string > content
Definition: YException.h:98
ystdex::cpp2014::result_of_t
typename result_of< _type >::type result_of_t
Definition: type_traits.hpp:355
platform::Descriptions::Alert
Definition: YCommon.h:164
YF_TraceRaw
#define YF_TraceRaw(_lv,...)
YFramework 跟踪。
Definition: Debug.h:279
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::FatalError
致命错误。
Definition: YException.h:90
platform::Deref
yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:451
CHRLib::f
f(d, s)
ystdex::nonvoid_result_t
cond_t< not_< is_void< _type >>, _type, pseudo_output > nonvoid_result_t
若类型不是空类型则取后备结果类型（默认为 pseudo_output ）。
Definition: ref.hpp:341
platform::Descriptions::Emergent
Definition: YCommon.h:163
YSLib::TryInvoke
ystdex::nonvoid_result_t< ystdex::result_of_t< _fCallable &&(_tParams &&...)> > TryInvoke(_fCallable &&f, _tParams &&...args) ynothrow
调用函数并尝试返回。
Definition: YException.h:186
YSLib::LoggedEvent
记录日志的异常事件类。
Definition: YException.h:50
TryRet
#define TryRet(...)
指定表达式在 try 块中求值并返回。
Definition: YBaseMacro.h:124
CHRLib::args
_tParams && args
Definition: CharacterProcessing.h:538
ystdex::invoke_nonvoid
nonvoid_result_t< result_of_t< _fCallable &&(_tParams &&...)> > invoke_nonvoid(_fCallable &&f, _tParams &&...args)
调用可调用对象，保证返回值非空。
Definition: functional.hpp:372
YSLib::RecordLevel
YF_API RecordLevel
Definition: YException.h:142
platform::Descriptions::RecordLevel
RecordLevel
记录等级。
Definition: YCommon.h:161
CatchExpr
#define CatchExpr(_ex,...)
指定表达式作为异常处理器。
Definition: YBaseMacro.h:129
YSLib::FilterExceptions
bool FilterExceptions(_func f, const char *desc={}, RecordLevel lv=Alert, ExceptionTracer trace=ExtractAndTrace) ynothrow
调用函数并过滤宿主异常。
Definition: YException.h:203
YSLib::ExceptionTracer
GLevelTracer< const std::exception & > ExceptionTracer
Definition: YException.h:134
YSLib::ExtractedLevelPrinter
std::function< void(const char *, RecordLevel, size_t)> ExtractedLevelPrinter
打印带有层次信息的函数类型。
Definition: YException.h:131
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::LoggedEvent::level
RecordLevel level
Definition: YException.h:54
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
functional.hpp
函数和可调用对象。
CHRLib::e
const char const char * e
Definition: CharacterProcessing.h:109
YSLib::YB_NONNULL
YF_API YB_NONNULL(1, 2) ValueNode LoadNPLA1File(const char *disp
载入 NPLA1 配置文件。
std
Definition: memory.hpp:1183
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
YSLib::GeneralEvent
std::runtime_error GeneralEvent
一般运行时异常事件类。
Definition: YException.h:46
platform::Descriptions::Err
Definition: YCommon.h:166
YModules.h
DefDeCopyCtor
#define DefDeCopyCtor(_t)
Definition: YBaseMacro.h:162
YSLib::TryExecute
YF_API bool TryExecute(std::function< void()>, const char *={}, RecordLevel=Alert, ExceptionTracer=ExtractAndTrace)
执行并尝试记录异常。
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:995
YSLib::GLevelTracer
std::function< void(_type, RecordLevel)> GLevelTracer
Definition: YException.h:133
YSLib::ExtractAndTrace
YF_API void ExtractAndTrace(const std::exception &, RecordLevel=Err) ynothrow
使用 TraceException 展开和跟踪异常类型和信息。
ystdex::string_view
basic_string_view< char > string_view
Definition: string_view.hpp:415
YSLib::ExtractException
YF_API void ExtractException(const ExtractedLevelPrinter &, const std::exception &, RecordLevel=Err, size_t=0) ynothrow
展开指定层次的异常并使用指定参数记录。
YSLib::lv
RecordLevel lv
Definition: YException.cpp:58