winrt::throw_hresult function (C++/WinRT)

A helper function that takes a HRESULT error code, and throws an exception using a C++/WinRT object (or a standard object) that represents that error code.

If the error code is E_OUTOFMEMORY, then std::bad_alloc is thrown. If the error code is a common HRESULT error code, then one of the specialized types derived from winrt::hresult_error is thrown. For example, E_INVALIDARG causes a winrt::hresult_invalid_argument to be thrown. Otherwise, winrt::hresult_error is thrown.

Syntax

[[noreturn]] inline __declspec(noinline) void throw_hresult(HRESULT const result);

Parameters

result An HRESULT code that represents the error that was encountered.

Requirements

Minimum supported SDK: Windows SDK version 10.0.17134.0 (Windows 10, version 1803)

Namespace: winrt

Header: %WindowsSdkDir%Include<WindowsTargetPlatformVersion>\cppwinrt\winrt\base.h (included by default)

See also