• Advertisement
Sign in to follow this  

Error Reporting

This topic is 4516 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a basic DirectX wrapper library. When a DirectX function fails, I need a way to report WHICH DirectX function it was that failed in string format. For example, my error report message box would appear as follows:
          DirectX Function Failure

          Function: IDirect3DDevice9::SetMaterial()
So far the only possible way I can think of doing this is by creating a constant identifier which represents each and every single DirectX function. So, for example, SetMaterial() would have a constant named MYLIBRARY_DEVICE_SETMATERIAL. This constant, in turn, would be submitted to a function which will create a string based on the constant. Here is a small example of what I'm talking about:
const char* CreateErrorString(int Constant)
{
    switch(Constant)
    {
    case MYLIBRARY_DEVICE_SETMATERIAL: return "IDirect3DDevice9::SetMaterial()";
    }

    return "Inappropriate Constant Specified";
}
All of this is very tedious and should be a last resort. Any easier way to achieve what I need?

Share this post


Link to post
Share on other sites
Advertisement
Why do you need to use constants? Why not just send the function name as a string?

void DX_WRAPPER::SetMaterial()
{
if(FAILED(m_pDevice->SetMaterial(blah))
errorHandler->processError("DX_WRAPPER::SetMaterial()");
}


I think windows even has something build in for stuff like this. I think there are variables that always store information about where you are in the code. For example I think __FUNCTION__ or something always stores the function you are in. I've never actually used this, just seen it in other modules.

Matt Hughson

Share this post


Link to post
Share on other sites
__FUNCTION__ only returns the CURRENT scope. So, in your example's context, it would return DX_WRAPPER::SetMaterial().

The reason why I would use constants is as follows:

1) Organization
2) Easily update the strings
3) Avoid duplicate strings


So, assume you have 20 calls to IDirect3DDevice9::SetMaterial() all over your library, you don't want to have to type or copy/paste the same string for each one. And if you want to go back later and make this string display differently, you'd have to modify all 20 strings instead of just one.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement