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

Raymond Chen

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

0 comments

Discussion is closed.

Feedback usabilla icon