0

As we know, C++ does not have reflection. However, when we throw an error, try-catch can determine which type of exception you are throwing. How does it work without reflection?

yzyzsun
  • 367
  • 4
  • 11
  • 2
    Possible duplicate of [How does the C++ runtime determine the type of a thrown exception?](http://stackoverflow.com/questions/993262/how-does-the-c-runtime-determine-the-type-of-a-thrown-exception) – Kevin Dec 10 '15 at 16:53
  • 1
    You are comparing compiler internals to what is offered to the programmer externally. These are two different things. – PaulMcKenzie Dec 10 '15 at 16:55

1 Answers1

1

Although C++ does not have a reflection exposed to programmers, there is a type information known to compiler. In particular, when C++ program executes, there are special provisions made so that every time a try block is entered, a special entry is made (somewhere, for example, in exception frame) that the exception of the particular compile-time type is ready to be handled at this location. When exception is thrown, the frame is consulted for nearest suitable handler.

SergeyA
  • 61,605
  • 5
  • 78
  • 137