YSTest: YException.h 源文件

YSTest PreAlpha_b700_20160611 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::result_of_t, ystdex::invoke;
38
39 namespace YSLib
40 {
41
43
44 using GeneralEvent = std::runtime_error;
46
47
49 class YF_API LoggedEvent : public GeneralEvent
50 {
51 private:
53 RecordLevel level;
54
55 public:
61 YB_NONNULL(2)
63 LoggedEvent(const char* = "", RecordLevel = Emergent);
64 LoggedEvent(const string_view, RecordLevel = Emergent);
66
70 LoggedEvent(const GeneralEvent&, RecordLevel = Emergent);
72 DefDeCopyCtor(LoggedEvent)
77 ~LoggedEvent() override;
78
80 DefGetter(const ynothrow, RecordLevel, Level, level)
81 };
82
83
89 class YF_API FatalError : public GeneralEvent
90 {
91 private:
97 shared_ptr<string> content;
98
99 public:
106 YB_NONNULL(2)
107 FatalError(const char*, string_view);
109 DefDeCopyCtor(FatalError)
114 ~FatalError() override;
115
117 DefGetter(const ynothrow, string_view, Content, Deref(content))
118 DefGetter(const ynothrow, const char*, Title, what())
119 };
121
122
124
125
129 using ExtractedLevelPrinter
130 = std::function<void(const char*, RecordLevel, size_t)>;
131 template<typename _type>
132 using GLevelTracer = std::function<void(_type, RecordLevel)>;
133 using ExceptionTracer = GLevelTracer<const std::exception&>;
134
135
140 YF_API YB_NONNULL(1) void
141 TraceException(const char*, RecordLevel = Err, size_t level = 0) ynothrow;
142
148 YF_API void
149 TraceExceptionType(const std::exception&, RecordLevel = Err) ynothrow;
150
158 YF_API void
159 ExtractAndTrace(const std::exception&, RecordLevel = Err) ynothrow;
160
162 YF_API void
163 ExtractException(const ExtractedLevelPrinter&,
164 const std::exception&, RecordLevel = Err, size_t = 0) ynothrow;
166
168
169
175 YF_API bool
176 TryExecute(std::function<void()>, const char* = {}, RecordLevel = Alert,
177 ExceptionTracer = ExtractAndTrace);
178
183 template<typename _fCallable, typename... _tParams>
184 ystdex::result_of_t<_fCallable&&(_tParams&&...)>
185 TryInvoke(_fCallable&& f, _tParams&&... args) ynothrow
186 {
187 TryRet(ystdex::invoke(yforward(f), yforward(args)...))
188 CatchExpr(std::exception& e, TraceExceptionType(e, Emergent))
189 CatchExpr(..., YCL_TraceRaw(Emergent, "Unknown exception found."))
190 return {};
191 }
192
200 template<typename _func>
201 bool
202 FilterExceptions(_func f, const char* desc = {}, RecordLevel lv = Alert,
203 ExceptionTracer trace = ExtractAndTrace) ynothrow
204 {
205 return !TryInvoke([=]{
206 return !TryExecute(f, desc, lv, trace);
207 });
208 }
210
211 } // namespace YSLib;
212
213 #endif
214
YSLib::lv
RecordLevel lv
Definition: YException.cpp:58
YSLib::FatalError
致命错误。
Definition: YException.h:89
ystdex::string_view
basic_string_view< char > string_view
Definition: string_view.hpp:415
YModules.h
YSLib::GeneralEvent
std::runtime_error GeneralEvent
一般运行时异常事件类。
Definition: YException.h:45
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
CHRLib::e
const char const char * e
Definition: CharacterProcessing.h:109
YSLib::FilterExceptions
bool FilterExceptions(_func f, const char *desc={}, RecordLevel lv=Alert, ExceptionTracer trace=ExtractAndTrace) ynothrow
调用函数并过滤宿主异常。
Definition: YException.h:202
CatchExpr
#define CatchExpr(_ex,...)
指定表达式作为异常处理器。
Definition: YBaseMacro.h:129
YSLib::LoggedEvent
记录日志的异常事件类。
Definition: YException.h:49
ystdex::invoke
result_of_t< _fCallable &&(_tParams &&...)> invoke(_fCallable &&f, _tParams &&...args)
调用可调用对象。
Definition: functional.hpp:337
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:240
platform::Descriptions::Emergent
Definition: YCommon.h:153
YSLib::RecordLevel
YF_API RecordLevel
Definition: YException.h:141
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
YSLib::TryInvoke
ystdex::result_of_t< _fCallable &&(_tParams &&...)> TryInvoke(_fCallable &&f, _tParams &&...args) ynothrow
调用函数并试图返回。
Definition: YException.h:185
functional.hpp
函数和可调用对象。
std
Definition: memory.hpp:1100
platform::Deref
yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:440
DefDeCopyCtor
#define DefDeCopyCtor(_t)
Definition: YBaseMacro.h:161
YSLib::FatalError::content
shared_ptr< string > content
Definition: YException.h:97
YCL_TraceRaw
#define YCL_TraceRaw(_lv,...)
YCLib 直接调试跟踪。
Definition: Debug.h:271
TryRet
#define TryRet(...)
指定表达式在 try 块中求值并返回。
Definition: YBaseMacro.h:124
YSLib::GLevelTracer
std::function< void(_type, RecordLevel)> GLevelTracer
Definition: YException.h:132
YSLib::ExceptionTracer
GLevelTracer< const std::exception & > ExceptionTracer
Definition: YException.h:133
YSLib::YB_NONNULL
YF_API YB_NONNULL(1, 2) ValueNode LoadNPLA1File(const char *disp
载入 NPLA1 配置文件。
YSLib::ExtractedLevelPrinter
std::function< void(const char *, RecordLevel, size_t)> ExtractedLevelPrinter
打印带有层次信息的函数类型。
Definition: YException.h:130
YSLib::LoggedEvent::level
RecordLevel level
Definition: YException.h:53
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:969
YSLib::TraceExceptionType
YF_API void TraceExceptionType(const std::exception &, RecordLevel=Err) ynothrow
通过 YCL_TraceRaw 跟踪记录异常类型。
platform::Descriptions::RecordLevel
RecordLevel
记录等级。
Definition: YCommon.h:151
YF_API
#define YF_API
Definition: Platform.h:56
platform::Descriptions::Err
Definition: YCommon.h:156
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::cpp2014::result_of_t
typename result_of< _type >::type result_of_t
Definition: type_traits.hpp:362
YSLib::TryExecute
YF_API bool TryExecute(std::function< void()>, const char *={}, RecordLevel=Alert, ExceptionTracer=ExtractAndTrace)
执行并试图记录异常。
YSLib::ExtractException
YF_API void ExtractException(const ExtractedLevelPrinter &, const std::exception &, RecordLevel=Err, size_t=0) ynothrow
展开指定层次的异常并使用指定参数记录。
YSLib::ExtractAndTrace
YF_API void ExtractAndTrace(const std::exception &, RecordLevel=Err) ynothrow
使用 TraceException 展开和跟踪异常类型和信息。
platform::Descriptions::Alert
Definition: YCommon.h:154