Inside the Microsoft STL: The std::exception_ptr
When debugging, you may find yourself staring at a
std::exception_ptr and want to know what exception is inside it.
What you see in the MSVC header file is that a
std::exception_ptr is a class that consists of two pointers enigmatically named
The dirty secret is that a
std::exception_ptr is a
std::shared_ptr in disguise.
_Data1 acts as the
_Ptr and points to the shared object. The
_Data2 acts as the
_Rep and points to the control block.
For debugging purposes, you can ignore the
_Data2 and focus on the
_Data1, which is a pointer to an
Once you have the
EXCEPTION_RECORD, you can use the
.exr command to view it, and then use the existing cookbook for extracting the thrown object and its type information.
In practice, you don’t usually need to go through the whole cookbook. The
Parameter points to the object that was thrown, and that object usually contains enough information to let you figure out what it is.
We’ll look at some of the possibilities next time.