Original Post
Whats the best method of error checking and handling when dealing with DirectX? Originally i thought about using exceptions, but decided against them in the end because you need a try/catch everywhere, you dont want a stray exception being thrown and not caught in a game! The other 2 options ive got are, using HRESULTS as return values for all functions, or, using booleans (and possibly having a global error state, which i can check if needed). And then logging all errors manually (i would prefer a more automatic way of reporting errors though...) Ive gone for the later option at the moment, but im not 100% about my code layout, i dont know if there is a better way:
bool CEngineVideo::ValidateVideo(void)
{
bool bReturn = false;
HRESULT hrResult = 0;
hrResult = m_pDevice->TestCooperativeLevel(); // Test the current state of the device
if (FAILED(hrResult))
{
// If the device is lost then return failure
if (hrResult == D3DERR_DEVICELOST)
LOGERROR("The device is lost");
// If the device is not ready to be reset then attempt to do so
else if (hrResult == D3DERR_DEVICENOTRESET)
{
// Reset the device
hrResult = m_pDevice->Reset(&m_SavedPresentParams);
if (FAILED(hrResult))
LOGERROR("Could not reset the device");
m_pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 0.0f, 0);
bReturn = this->RestoreVideo();
}
}
return bReturn;
}