This repository was archived by the owner on Aug 16, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ int main(int argc, char* argv[])
6060因为其中的函数数量比较多,而且作者精力有限,因此不提供详细的使用文档,具体如何使用请查看 [MiraiBot](https://github.com/cyanray/mirai-cpp/blob/master/include/mirai/mirai_bot.hpp) 类的注释以及 [examples](https://github.com/cyanray/mirai-cpp/tree/master/examples) 目录里的示例。
6161
6262你可能想了解:
63+ * [详细示例(简易复读机Bot)](https://github.com/cyanray/mirai-cpp/blob/master/examples/RepeatMessage.cpp)
6364* [详细文档](doc/Documentation.md)
6465* [如何与mirai-api-http建立连接](doc/Documentation.md#如何与mirai-api-http建立连接)
6566* [如何接收、处理事件](doc/Documentation.md#如何接收、处理事件)
Original file line number Diff line number Diff line change @@ -628,6 +628,27 @@ bot.On<LostConnection>([&](LostConnection e)
628628 });
629629```
630630
631+ 此外,在解析事件时可能会遇到异常(比如收到了错误的 JSON),这些异常默认会被捕捉然后丢弃,你也可以使用 On 函数捕获 EventParsingError 事件来了解这些异常。
632+ 这个事件并不常用,一般用于调试的需要。
633+ 比如 mirai 收到了一个事件,但是 mirai-cpp 没有触发对应的事件处理函数,那么可能是因为这个事件没能被 mirai-cpp 解析。
634+
635+ 下面的代码使用 `Rethrow()` 函数重新抛出了解析事件时的异常。
636+
637+ ```c++
638+ bot.On<EventParsingError>([&](EventParsingError e)
639+ {
640+ try
641+ {
642+ e.Rethrow();
643+ }
644+ catch (const std::exception& ex)
645+ {
646+ cout << "解析事件时出现错误: " << ex.what() << endl;
647+ }
648+ });
649+ ```
650+
651+
631652## 其他
632653
633654### ToJson和ToSting
You can’t perform that action at this time.
0 commit comments