winrt::hresult_error 結構 (C++/WinRT)

表示 HRESULT 錯誤碼的類型。

語法

struct hresult_error

規格需求

最低支援的 SDK:Windows SDK 10.0.17134.0 版 (Windows 10版本 1803)

命名空間: winrt

標頭: %WindowsSdkDir%IncludeWindowsTargetPlatformVersion <> \cppwinrt\winrt\base.h 預設包含 ()

建構函式

建構函式 描述
hresult_error::hresult_error 建構函式 使用輸入資料的複本,初始化 hresult_error 結構的新實例。

類型

建構函式 描述
hresult_error::from_abi_t類型 hresult_error::from_abi靜態資料成員的類型。

靜態資料成員

函式 描述
hresult_error::from_abi靜態資料成員 類型 為 hresult_error::from_abi_t的實例,可以傳遞至 hresult_error ( 的建構函式或衍生類型) ,表示建構函式應該嘗試擷取受限制的錯誤資訊。

成員函數

函式 描述
hresult_error::code 函式 擷取 hresult_error 物件所表示之錯誤的程式碼。
hresult_error::message 函式 擷取 hresult_error 物件所表示之錯誤的訊息。
hresult_error::to_abi 函式 設定目前線程的受限制錯誤資訊物件,並傳回 hresult_error 物件所表示之錯誤的程式碼。
hresult_error::try_as 函式 如果支援,則傳回要求的介面。 如果不是 ,則傳 nullptr 回 或 false

成員運算子

運算子 描述
hresult_error::operator= (指派運算子) 將值指派給 hresult_error 物件。

hresult_error::hresult_error 建構函式

使用輸入資料的複本,初始化 hresult_error 結構的新實例。

語法

hresult_error() noexcept;
hresult_error(hresult_error&&);
hresult_error(hresult_error const& other);
explicit hresult_error(HRESULT const code) noexcept;
hresult_error(HRESULT const code, winrt::hstring const& message, ::IUnknown* object = nullptr) noexcept;
hresult_error(HRESULT const code, winrt::hresult_error::from_abi_t) noexcept;

參數

other另一個初始化hresult_error物件的hresult_error

code 初始化 hresult_error 物件的 HRESULT 程式碼。

message 資訊字串,可協助開發人員更正回報的錯誤狀況。

object 錯誤物件,儲存有關錯誤的額外資訊。 錯誤物件應該是 Apartment-agile、in-proc 和 marshal-by-value 跨進程。 它應該視需要實作 ILanguageExceptionStackBackTraceILanguageExceptionTransform 。 請參閱 RoOriginateLanguageException

hresult_error::code 函式

擷取 hresult_error 物件所表示之錯誤的程式碼。

語法

winrt::hresult code() const noexcept;

傳回值

winrt::hresult錯誤碼。

hresult_error::from_abi靜態資料成員

類型 為 hresult_error::from_abi_t的實例,可以傳遞至 hresult_error ( 的建構函式或衍生類型) ,表示建構函式應該嘗試擷取受限制的錯誤資訊。

語法

static constexpr winrt::hresult_error::from_abi_t from_abi{};

hresult_error::from_abi_t類型

hresult_error::from_abi靜態資料成員的類型。

語法

struct from_abi_t {};

hresult_error::message 函式

擷取 hresult_error 物件所表示之錯誤的訊息。

語法

winrt::hstring message() const noexcept;

傳回值

包含錯誤混亂的 winrt::hstring

hresult_error::operator= (指派運算子)

將值指派給 hresult_error 物件。

語法

winrt::hresult_error& operator=(winrt::hresult_error&&);
winrt::hresult_error& operator=(winrt::hresult_error const& other) noexcept;

參數

other要指派給hresult_error物件的hresult_error值。

傳回值

hresult_error物件的參考。

hresult_error::to_abi 函式

設定目前線程的受限制錯誤資訊物件,並傳回 hresult_error 物件所表示之錯誤的程式碼。

語法

HRESULT to_abi() const noexcept;

傳回值

HRESULT 錯誤碼。

hresult_error::try_as 函式

如果支援,則傳回要求的介面。 如果不是,則傳 nullptr 回 。 如果您想要查詢不需要傳回給呼叫端的介面,此函式會很有用。 例如,您可以擷取 IRestrictedErrorInfo ,以存取 hresult_error 物件所代表之錯誤的受限制錯誤資訊。

語法

template <typename To> auto try_as() const noexcept;

範本參數

typename To 要求的介面類別型。

參數

to 要接收所要求介面之值的參考。

傳回值

winrt::com_ptr參考要求的介面,或要求之介面的強型別智慧指標, (C++/WinRT 或協力廠商所宣告的智慧型別) ,否則 nullptr 為 。

另請參閱