Re: exception handling when RTTI is turned off in VC8
John wrote:
{ This question looks like an environment-specific one, but shall we
regard it as a special case of many possible outcomes in general,
and not go too far into details of a specific environment. -mod/sk }
Can anyone please explain how exception is handled properly when RTTI
is turned off in VC8? Thanks.
Exception handling do need type information when choosing exception handler.
It's NOT necessary to use RTTI for exception handling.
I was once told that VC6 uses RTTI for exception handling, while VC8
uses different structures.
15.1/3
A throw-expression initializes a temporary object, called the exception
object, the type of which is determined by removing any top-level
cv-qualifiers from the *static type* of the operand of throw and
adjusting the type from ?array of T? or ?function returning T? to
?pointer to T? or ?pointer to function returning T?, respectively.
So maybe RTTI overkills, we can use simpler lighter type information for
exception handling.
<code>
#include <iostream>
#include <typeinfo>
struct Base
{
virtual ~Base() {}
};
struct Derived : Base {};
void Fun(Base& b)
{
std::cout << typeid(b).name() << std::endl;
throw b;
}
int main()
{
try {
Derived d;
Fun(d);
}
catch (Derived&) {
std::cout << "catch a Derived" << std::endl;
}
catch (Base&) {
std::cout << "catch a Base" << std::endl;
}
}
</code>
outputs:
struct Derived
catch a Base
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]