c++;尝试/捕捉iOS中的无知 在我们的应用程序中,我们有一个C++静态库,我使用ObjtoVC++来处理它。 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; }

c++;尝试/捕捉iOS中的无知 在我们的应用程序中,我们有一个C++静态库,我使用ObjtoVC++来处理它。 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; },c++,ios,compiler-errors,xcode7,rapidjson,C++,Ios,Compiler Errors,Xcode7,Rapidjson,问题是,如果无法通过GetInt()方法将文档[“openFrom”]转换为Int,则不会引发异常。相反,我的应用程序因SIGABRT崩溃 Assertion failed: (data_.f.flags & kIntFlag), function GetInt, file /Users/xxx/xxx/xx/ios/../src/rapidjson/document.h, line 1645. 在Android操作系统上,顺便说一句,在相同的情况下,异常成功引发。 有什么问题吗?我想

问题是,如果无法通过GetInt()方法将文档[“openFrom”]转换为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
,它代表“信号中止”。断言在释放模式下被禁用,因此在那里应该可以正常工作。或者可以在rapidjson中禁用断言(通过定义宏
rapidjson\u ASSERT
)。

如果将其更改为
catch(const std::exception&e)
,会发生什么?另外,您确定
GetInt()
返回从
std::exception
派生的内容吗?@NathanOliver这是我尝试做的第一件事,但没有帮助。我不擅长C++,只是想知道同样的事情:在这种情况下(当GETIN()不能将输入文本转换成整数)时,异常不会被提升。它如何依赖于编译器/操作系统(在Android操作系统上,异常是raise和catch block的动作)看起来是一个解决方案。问题在于,它们在发布模式下(在方案设置->存档->构建配置中设置)没有被禁用。不管怎样,我会在rapidjson,tnx里面试着禁用它们!