在我们的应用程序中,我们有一个C++静态库,我使用Objective-C++来处理它。 即C++库利用rapidjson解析XML数据:iOS中的try/catch无知
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;
}
的问题是,如果文档[“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 OS上,顺便说一句,在同样的情况下,异常成功提升。 可能是什么问题?我想这个问题是在Xcode的Swift编译器行为。
如果将其更改为catch(const std :: exception&e)'会发生什么?你也确定'GetInt()'返回从std :: exception'派生的东西吗? – NathanOliver
@NathanOliver这是我尝试做的第一件事,没有帮助。我不擅长C++,只是想知道同样的事情:在这种情况下(当GetInt()不能将输入文本转换为整数)时,怎么可能不会引发异常。以及它如何依赖编译器/操作系统(如在Android OS上,例外情况是raise和catch block采取行动) – autobot