Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a relation between RTTI and exceptions?

I remember coding on platforms that had both RTTI and exceptions disabled, and on others that had them both enabled. However, I cannot remember coding on a platform that would enable one and disable the other one.

Is there any kind of dependency between the two concepts? Said differently, do exceptions need RTTI to function? Or the contrary?

like image 406
qdii Avatar asked Apr 25 '12 16:04

qdii


2 Answers

No, Exceptions do not need RTTI functionality neither vice versa both are separate features.

Some of the implementations might allow you to disable exceptions(-fnoexceptions in gcc) but I don't know of any implementation which needs RTTI for exceptions or vice versa.

like image 72
Alok Save Avatar answered Sep 20 '22 06:09

Alok Save


I was just reading this C++ proposal "Zero-overhead deterministic exceptions: Throwing values" (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0709r0.pdf?), in which I read:

"C++ allows there to be multiple active exception objects of arbitrary types, which must have unique addresses and cannot be folded; and it requires using RTTI to match handlers at run time, which has statically unpredictable cost on all major implementations and can depend on what else is linked into the whole program."

and elsewhere it is stated that:

"4) Today’s dynamic exceptions require using some form of RTTI to match handlers."

Thus, it appears there is a relation between exceptions and RTTI

like image 26
sjoerd Avatar answered Sep 23 '22 06:09

sjoerd