What is DX :: ThrowIfFailed?

Recently, I am returning to C ++. I have been away from C ++ / CLI using C # instead for at least a year, and I'm a little rusty. I am looking at a basic example for a Direct3D application for Windows 8 and cannot find anything that explains that

DX::ThrowIfFailed 

does. From the fact that he says that he will do something if something in DirectX fails, but from the implementation it seems that he is used to initialize the material, since the base for 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 that this is meticulous in the examples, but no number of search queries facilitated proper documentation. Thanks in advance!

+6
source share
1 answer

This function translates an HRESULT failure into exceptions. It is defined in DirectXHelper.h, which is part of the Direct3D application 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 containing the definition and move to its location.

+9
source

All Articles