November 28th, 2022

What kind of caller diagnostic information can I get from exceptions thrown by C++/WinRT and wil?, C++20 edition

A short time ago, I summarized the kind of caller diagnostic information you can get from exceptions thrown by C++/WinRT and wil. My colleague David Machaj reminded me that the story had improved in the time since I originally wrote the article, so it’s time for an update.

Starting in version 2.0.220929.3 of C++/WinRT, if std::source_location is supported, then C++/WinRT uses it to pass file and line number information to wil when a C++/WinRT exception is thrown. In practice, this happens when you compile in C++20 mode or later.

The revised table now looks like this:

  C++/WinRT wil
no wil/cppwinrt.h with wil/cppwinrt.h no C++/CX with C++/CX
throw hresult_error check_hresult THROW_IF_FAILED THROW_IF_FAILED
Thrown type hresult_error hresult_error hresult_error Result­Exception Exception^
Stack trace in thrown object Yes Yes Yes No Yes
Stack trace in thread data Yes Yes Yes Requires result_originate.h Yes
File/line number in thrown object No No No Yes No
Exception in wil error log No No Yes Yes Yes
File/line number in wil error log No Requires C++20 Requires C++20 Yes Yes
Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.