YSTest: YException.cpp 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

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

- 文件列表
- 文件成员

YException.cpp
浏览该文件的文档.
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 #include "YSLib/Core/YModules.h"
29 #include YFM_YSLib_Core_YException
30 #include <ystdex/exception.h> // for ystdex::handle_nested;
31
32 namespace YSLib
33 {
34
35 LoggedEvent::LoggedEvent(const char* str, RecordLevel lv)
36 : GeneralEvent(Nonnull(str)),
37 level(lv)
38 {}
39 LoggedEvent::LoggedEvent(string_view sv, RecordLevel lv)
40 : GeneralEvent(std::string(sv)),
41 level(lv)
42 {}
43 LoggedEvent::LoggedEvent(const GeneralEvent& e, RecordLevel lv)
44 : GeneralEvent(e),
45 level(lv)
46 {}
47 ImplDeDtor(LoggedEvent)
48
49
50 FatalError::FatalError(const char* t, string_view c)
51 : GeneralEvent(Nonnull(t)),
52 content((Nonnull(c.data()), make_shared<string>(string(c))))
53 {}
54 ImplDeDtor(FatalError)
55
56
57 void
58 TraceException(const char* str, RecordLevel lv, size_t level) ynothrow
59 {
60 TryExpr(
61 YF_TraceRaw(lv, "%s%s", std::string(level, ' ').c_str(), Nonnull(str)))
62 CatchExpr(..., YF_TraceRaw(Critical, "Failure @ TraceException."))
63 }
64
65 void
66 TraceExceptionType(const std::exception& e, RecordLevel lv) ynothrow
67 {
68 YF_TraceRaw(lv, "Caught std::exception[%s].", typeid(e).name());
69 }
70
71 void
72 ExtractAndTrace(const std::exception& e, RecordLevel lv) ynothrow
73 {
74 TraceExceptionType(e, lv);
75 ExtractException(TraceException, e, lv);
76 }
77
78 void
79 ExtractException(const ExtractedLevelPrinter& print, const std::exception& e,
80 RecordLevel lv, size_t level) ynothrow
81 {
82 TryExpr(print(e.what(), lv, level))
83 CatchExpr(..., print("Exception occurred when printing @ ExtractException.",
84 Critical, level))
85 TryExpr(ystdex::handle_nested(e,
86 [&, lv, level](std::exception& ex) ynothrow{
87 ExtractException(print, ex, lv, level + 1);
88 }))
89 CatchExpr(..., print("Unknown nested exception found nested on calling"
90 " ystdex::handle_nested @ ExtractException.", Critical, level))
91 }
92
93 bool
94 TryExecute(std::function<void()> f, const char* desc, RecordLevel lv,
95 ExceptionTracer trace)
96 {
97 try
98 {
99 TryExpr(f())
100 catch(...)
101 {
102 if(desc)
103 YF_TraceRaw(Notice, "Exception filtered: %s.", desc);
104 throw;
105 }
106 return {};
107 }
108 CatchExpr(std::exception& e, trace(e, lv))
109 return true;
110 }
111
112 } // namespace YSLib;
113
YSLib::TraceExceptionType
YF_API void TraceExceptionType(const std::exception &, RecordLevel=Err) ynothrow
通过 YF_TraceRaw 跟踪记录异常类型。
ystdex::handle_nested
void handle_nested(_tEx &e, _func &&f)
处理嵌套异常。
Definition: ystdex/exception.h:97
YF_TraceRaw
#define YF_TraceRaw(_lv,...)
YFramework 跟踪。
Definition: Debug.h:279
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::FatalError
致命错误。
Definition: YException.h:90
YSLib::ImplDeDtor
ImplDeDtor(LoggedEvent) FatalError
Definition: YException.cpp:47
CHRLib::f
f(d, s)
NPL::c_str
YF_API const char src c_str())) YF_API void InstallDirectory(const string &
安装目录：复制目录树。
Definition: Dependency.h:131
YSLib::LoggedEvent
记录日志的异常事件类。
Definition: YException.h:50
ystdex::make_shared
std::shared_ptr< _type > make_shared(std::initializer_list< _tValue > il)
使用指定类型的初始化列表构造指定类型的 std::shared_ptr 对象。
Definition: memory.hpp:945
platform::containers::string
basic_string< char > string
Definition: Container.h:101
ystdex::data
auto data(_tRange &c) -> decltype(c.data())
Definition: range.hpp:280
YSLib::RecordLevel
YF_API RecordLevel
Definition: YException.h:142
platform::Descriptions::RecordLevel
RecordLevel
记录等级。
Definition: YCommon.h:161
TryExpr
#define TryExpr(...)
指定表达式在 try 块中求值。
Definition: YBaseMacro.h:120
YSLib::level
YF_API size_t level
Definition: YException.h:142
CatchExpr
#define CatchExpr(_ex,...)
指定表达式作为异常处理器。
Definition: YBaseMacro.h:129
YSLib::ExceptionTracer
GLevelTracer< const std::exception & > ExceptionTracer
Definition: YException.h:134
ystdex
特性测试宏。
Definition: ydef.h:822
platform::Descriptions::Critical
Definition: YCommon.h:165
YSLib::ExtractedLevelPrinter
std::function< void(const char *, RecordLevel, size_t)> ExtractedLevelPrinter
打印带有层次信息的函数类型。
Definition: YException.h:131
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
platform::Descriptions::Notice
Definition: YCommon.h:168
YSLib::LoggedEvent::LoggedEvent
LoggedEvent(const string_view, RecordLevel=Emergent)
Definition: YException.cpp:39
exception.h
CHRLib::e
const char const char * e
Definition: CharacterProcessing.h:109
std
Definition: memory.hpp:1183
platform::Nonnull
_type && Nonnull(_type &&p) ynothrowv
断言并返回非空参数。
Definition: Debug.h:422
YSLib::GeneralEvent
std::runtime_error GeneralEvent
一般运行时异常事件类。
Definition: YException.h:46
YModules.h
YSLib::TryExecute
YF_API bool TryExecute(std::function< void()>, const char *={}, RecordLevel=Alert, ExceptionTracer=ExtractAndTrace)
执行并尝试记录异常。
YSLib::UI::name
yconstfn const string & name
Definition: Loader.h:130
YSLib::Text::str
const char const char * str
Definition: TextFile.h:81
CHRLib::c
c
Definition: CharacterProcessing.h:81
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