{"id":104097,"date":"2020-08-20T07:00:00","date_gmt":"2020-08-20T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=104097"},"modified":"2020-09-09T06:12:27","modified_gmt":"2020-09-09T13:12:27","slug":"20200820-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20200820-00\/?p=104097","title":{"rendered":"Inside the Microsoft STL: The std::exception_ptr"},"content":{"rendered":"<p>When debugging, you may find yourself staring at a <code>std::exception_ptr<\/code> and want to know what exception is inside it.<\/p>\n<p>What you see in the MSVC header file is that a <code>std::exception_ptr<\/code> is a class that consists of <a href=\"https:\/\/github.com\/microsoft\/STL\/blob\/b3504262fe51b28ca270aa2e05146984ef758428\/stl\/inc\/exception#L300\"> two pointers enigmatically named <code>_Data1<\/code> and <code>_Data2<\/code><\/a>.<\/p>\n<p>The dirty secret is that a <code>std::exception_ptr<\/code> is a <code>std::shared_ptr<\/code> in disguise.<\/p>\n<p><b>Prerequisite<\/b>: <a href=\"https:\/\/channel9.msdn.com\/Series\/C9-Lectures-Stephan-T-Lavavej-Advanced-STL\/C9-Lectures-Stephan-T-Lavavej-Advanced-STL-1-of-n\"> Advanced STL, part 1: <code>shared_ptr<\/code><\/a> by <a href=\"https:\/\/twitter.com\/StephanTLavavej\"> Stephan T. Lavavej<\/a>.<\/p>\n<p>The <code>_Data1<\/code> acts as the <code>_Ptr<\/code> and points to the shared object. The <code>_Data2<\/code> acts as the <code>_Rep<\/code> and points to the control block.<\/p>\n<p>For debugging purposes, you can ignore the <code>_Data2<\/code> and focus on the <code>_Data1<\/code>, which is a pointer to an <code>EXCEPTION_RECORD<\/code>.<\/p>\n<p>Once you have the <code>EXCEPTION_RECORD<\/code>, you can use the <code>.exr<\/code> command to view it, and then use <a title=\"Decoding the parameters of a thrown C++ exception (0xE06D7363)\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20100730-00\/?p=13273\"> the existing cookbook<\/a> for extracting the thrown object and its type information.<\/p>\n<p>In practice, you don&#8217;t usually need to go through the whole cookbook. The <code>Parameter[1]<\/code> points to the object that was thrown, and that object usually contains enough information to let you figure out what it is.<\/p>\n<p>We&#8217;ll look at some of the possibilities next time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Digging inside, for debugging purposes.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-104097","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Digging inside, for debugging purposes.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/104097","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=104097"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/104097\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=104097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=104097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=104097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}