
Felipe Magno de Almeida wrote:
I believe that get_exception_info makes a great difference! Obligating your users to use dynamic_cast you're making dynamic_cast being part of the interface of your library. Which makes no sense, dynamic_casts should be an implementation detail. And implementation details shouldnt be exposed by the interface.
I agree with you in principle, but I believe this case is an exception to that principle. For the exception library to work, the object thrown by throw failed<T>() must derive from T and from exception_info. If it was some other library, there are other implementations possible: maybe to make exception_info a member, or whatever. But because the whole point is to be able to catch(exception_info &), and to catch(T&), the exception type must derive from both. Therefore users know that dynamic_cast will work, with or without get_exception_info. People use interfaces to allow for different implementation strategies. But the only implementation possible for get_exception_info is to use dynamic_cast! Therefore, to me anyway, get_exception_info's purpose is to hide the dynamic_cast so I don't get emails like "why do you have a dynamic_cast as part of your interface". It's not part of the interface, it's part of C++. It does exactly what you need when you catch(T&) and want to see if you can get an exception_info *. --Emil