In gcc 4.2, this works:
#include <stdexcept>
#include <iostream>
int main() {
try {
throw std::runtime_error("abc");
} catch (const std::exception& ex) {
std::cout << ex.what();
}
}
In Xcode 4.3.2 (iOS with LLVM 3.1, -std=c++11), this fails with terminate called throwing an exception, never reaching the NSLog(…) line:
#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);
}
But this works:
#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);
}
What gives?
gcc is correct:
15.3p3 A handler is a match for an exception object of type
Eif
- ... or
- the handler is of type cv
Tor cvT&andTis an unambiguous public base class ofE, or- ...
This sounds like an xcode bug (and a surprisingly basic one!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With