c++ try/catch ignorance in iOS

c++ try/catch ignorance in iOS

本文关键字:in iOS ignorance catch try c++      更新时间:2023-10-16

在我们的应用程序中,我们有一个c++静态库,我使用objective - c++来处理它。c++库使用rapidjson解析XML数据:

try {
            rapidjson::Document document;
            document.Parse(connection.data.description);
            connection.openTime = document["openFrom"].GetInt();
            connection.closeTime = document["openTo"].GetInt();
            return true;
        } catch (std::exception e) {
            connection.openTime = 0;
            connection.closeTime = 0;
            return false;
        }

问题是,如果document["openFrom"]不能通过GetInt()方法转换为Int,则不会引发异常。而不是我的应用程序崩溃的SIGABRT。

Assertion failed: (data_.f.flags & kIntFlag), function GetInt, file /Users/xxx/xxx/xx/ios/../src/rapidjson/document.h, line 1645.
在Android操作系统上,顺便说一句,在相同的情况下,异常会成功引发。有什么问题吗?我猜问题是在Xcode的Swift编译器的行为

正如您提供的日志中明确指出的那样-这不是崩溃,它只是一个内部调用abort()的失败断言,导致SIGABRT代表'信号中止'。断言在发布模式下被禁用,所以它应该在那里工作得很好。或者你可以禁用断言在快速json(通过定义宏RAPIDJSON_ASSERT)。