在 gcc 4.2 中,这有效:
#include <stdexcept>
#include <iostream>
int main() {
try {
throw std::runtime_error("abc");
} catch (const std::exception& ex) {
std::cout << ex.what();
}
}
在 Xcode 4.3.2(带有 LLVM 3.1 的 iOS,-std=c++11)中,这失败了terminate called throwing an exception
,永远不会到达该NSLog(…)
行:
#include <stdexcept>
int main() {
try {
throw std::runtime_error("abc");
} catch (const std::exception& ex) {
NSLog(@"%s", ex.what());
}
return UIApplicationMain(argc, argv, nil, nil);
}
但这有效:
#include <stdexcept>
int main() {
try {
throw std::runtime_error("abc");
} catch (const std::runtime_error& ex) {
NSLog(@"%s", ex.what());
}
return UIApplicationMain(argc, argv, nil, nil);
}
是什么赋予了?