ObjC++ code fails to catch exceptions by baseclass, works in pure C++
| Originator: | satsumac | ||
| Number: | rdar://11950976 | Date Originated: | 25-Jul-2012 |
| Status: | Resolved: | ||
| Product: | Developer Tools | Product Version: | 4.3.3+ |
| Classification: | Serious Bug | Reproducible: | Always |
Summary:
ObjC++ code fails to catch exceptions by baseclass when run from a "Foundation" tool/app. Same code works when run from a pure "C++" tool/app.
Steps to Reproduce:
1. Embed this code snippet into a "Foundation" command-line tool project:
#include <iostream>
#include <stdexcept>
//. . .
try {
throw std::invalid_argument("Ecky ecky ecky ecky pakang zoom boing!");
}
catch(const std::exception &e) {
std::cout << "Exception raised: " << e.what() << std::endl;
}
catch( ... ){
std::cout << "Unknown exception raised!" << std::endl;
}
try {
throw std::invalid_argument("Ecky ecky ecky ecky pakang zoom boing!");
}
catch(const std::invalid_argument &e) {
std::cout << "Exception raised: " << e.what() << std::endl;
}
catch( ... ){
std::cout << "Unknown exception raised!" << std::endl;
}
2. Run it.
Expected Results:
// Correct output:
// Exception raised: Ecky ecky ecky ecky pakang zoom boing!
// Exception raised: Ecky ecky ecky ecky pakang zoom boing!
Actual Results:
// Wrong output:
// Unknown exception raised!
// Exception raised: Ecky ecky ecky ecky pakang zoom boing!
Doing the same within a "C++" command-line tool project results in correct output. Same code. No changes.
Notes:
Found this stack overflow question dealing with the same issue:
http://stackoverflow.com/questions/10602726/xcode-llvm-catch-clause-not-matching-derived-types
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!