I have been getting back into C++ lately. I've been away from C++/CLI using C# instead for at least a year now and I am a bit rusty. I am looking at the base example for a Direct3D app for Windows 8 and cannot find anything that explains what the
DX::ThrowIfFailed
does. From what it says it will execute something if something in DirectX failed, but from the implementation it looks like it is being used for initializing stuff as the base for the Direct3D demonstrates:
Platform::String^ text = "Hello, DirectX!";
DX::ThrowIfFailed(
m_dwriteFactory->CreateTextLayout(
message->Data(),
message->Length(),
m_textFormat.Get(),
700, // maxWidth.
1000, // maxHeight.
&m_textLayout
)
);
Can someone explain to me how this function works. I see it scattared accross examples but no amount of googling has relieved proper documentation. Thank you ahead of time!
This function translates failure HRESULTs into exceptions. It is defined like so, in DirectXHelper.h, which is part of the Direct3D App template:
inline void ThrowIfFailed(HRESULT hr)
{
if (FAILED(hr))
{
// Set a breakpoint on this line to catch Win32 API errors.
throw Platform::Exception::CreateException(hr);
}
}
If you are using Visual Studio, you can right-click on any instance of ThrowIfFailed
in the code and select "Go To Definition." This will open the file that contains the definition and navigate to its location.
For more information on this helper, see GitHub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With