Dear, Xcode User's Mailing LIst:
The other day I ran across a really strange occurrence in Xcode, where one of my test cases was failing when compiled and run in Release build configuration yet passed in Debug mode. This would indicate that there is a mismatched setting(s) between Release and Debug, but all the settings are as correct from what I can tell. The project that I'm working on is a C++ dynamic library, which is built in a one target and the CppUnit test cases in another.
Now what's really weird, is that the test cases that do fail are all doing the some sort of thing: they are testing a non-inline method that is throwing an exception which I've written and which derives from std::exception. After doing a quick test, I'm only observing this issue with my exceptions thrown from non-inline methods.
For example, consider the following header file:
#include <exception>
class FooException : public virtual std::exception {
public:
FooException() throw () : std::exception() { return; }
~ FooException() throw () { return; }
virtual const char* what() const throw()
{
return "FooException";
}
};
class Bar {
....
public:
inline void throwFoo throw (FooException)
{
throw FooException();
}
};
This works just fine (passes test case).
However this does not; header file:
#include <exception>
class FooException : public virtual std::exception {
public:
FooException() throw () : std::exception() { return; }
~ FooException() throw () { return; }
virtual const char* what() const throw()
{
return "FooException";
}
};
class Bar {
....
public:
void throwFoo throw (FooException);
};
Cpp file:
void Bar::throwFoo throw (FooException)
{
throw FooException();
}
In this later case, looking at the results form the try-catch block, the thrown exception from throwFoo, the What() is a "FooException" however it is not caught as such is Why would this two different
try{
Bar bar;
bar.throwFoo();
}catch(FooException& e){
std::cout << "Caught FooException\n";
}catch(std::exception& e){
std::cout << "Caught std::exception\n";
}
In Release mode, "Caught std::exception" would be printed out, but in Debug "Caught FooException". Any ideas why? Why are the exception types getting confused? Again, this only happens with non-inline methods.
Thanks,
Matthew