# Error Reporting

## 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 on other sites
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 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 on other sites
What about combining __FUNCTION__, __FILE__ and __LINE__ then?

Matt Hughson

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628385
• Total Posts
2982391

• 10
• 9
• 15
• 24
• 11