{"id":107469,"date":"2022-11-28T07:00:01","date_gmt":"2022-11-28T15:00:01","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=107469"},"modified":"2022-11-26T08:21:06","modified_gmt":"2022-11-26T16:21:06","slug":"20221128-01","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20221128-01\/?p=107469","title":{"rendered":"What kind of caller diagnostic information can I get from exceptions thrown by C++\/WinRT and wil?, C++20 edition"},"content":{"rendered":"<p>A short time ago, I summarized <a title=\"What kind of caller diagnostic information can I get from exceptions thrown by C++\/WinRT and wil?\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20221121-00\/?p=107429\"> the kind of caller diagnostic information you can get from exceptions thrown by C++\/WinRT and wil<\/a>. My colleague <a href=\"https:\/\/github.com\/dmachaj\">David Machaj<\/a> reminded me that the story had improved in the time since I originally wrote the article, so it&#8217;s time for an update.<\/p>\n<p>Starting in version 2.0.220929.3 of C++\/WinRT, if <code>std::<wbr \/>source_location<\/code> is supported, then C++\/WinRT uses it <a href=\"https:\/\/github.com\/microsoft\/cppwinrt\/pull\/1185\"> to pass file and line number information to wil<\/a> when a C++\/WinRT exception is thrown. In practice, this happens when you compile in C++20 mode or later.<\/p>\n<p>The revised table now looks like this:<\/p>\n<table style=\"border-collapse: collapse; font-size: 80%;\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n<tbody>\n<tr>\n<th rowspan=\"3\">\u00a0<\/th>\n<th colspan=\"3\">C++\/WinRT<\/th>\n<th colspan=\"2\">wil<\/th>\n<\/tr>\n<tr>\n<th rowspan=\"2\">no <code>wil\/<wbr \/>cppwinrt.h<\/code><\/th>\n<th colspan=\"2\">with <code>wil\/<wbr \/>cppwinrt.h<\/code><\/th>\n<th>no C++\/CX<\/th>\n<th>with C++\/CX<\/th>\n<\/tr>\n<tr>\n<th><code>throw hresult_<wbr \/>error<\/code><\/th>\n<th><code>check_<wbr \/>hresult<\/code><\/th>\n<th><code>THROW_<wbr \/>IF_<wbr \/>FAILED<\/code><\/th>\n<th><code>THROW_<wbr \/>IF_<wbr \/>FAILED<\/code><\/th>\n<\/tr>\n<tr>\n<td>Thrown type<\/td>\n<td><code>hresult_<wbr \/>error<\/code><\/td>\n<td><code>hresult_<wbr \/>error<\/code><\/td>\n<td><code>hresult_<wbr \/>error<\/code><\/td>\n<td><code>Result\u00adException<\/code><\/td>\n<td><code>Exception^<\/code><\/td>\n<\/tr>\n<tr>\n<td>Stack trace in thrown object<\/td>\n<td>Yes<\/td>\n<td>Yes<\/td>\n<td>Yes<\/td>\n<td>No<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>Stack trace in thread data<\/td>\n<td>Yes<\/td>\n<td>Yes<\/td>\n<td>Yes<\/td>\n<td>Requires <code>result_<wbr \/>originate.h<\/code><\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>File\/line number in thrown object<\/td>\n<td>No<\/td>\n<td>No<\/td>\n<td>No<\/td>\n<td>Yes<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>Exception in wil error log<\/td>\n<td>No<\/td>\n<td>No<\/td>\n<td>Yes<\/td>\n<td>Yes<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>File\/line number in wil error log<\/td>\n<td>No<\/td>\n<td>Requires C++20<\/td>\n<td>Requires C++20<\/td>\n<td>Yes<\/td>\n<td>Yes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>The state of the art has moved forward slightly.<\/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-107469","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The state of the art has moved forward slightly.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/107469","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=107469"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/107469\/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=107469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=107469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=107469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}