Archived

This topic is now archived and is closed to further replies.

Error handling...

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

Recommended Posts

In Unreal when an error occurs a dialog is shown containing the function call where the error occurred on, something like this: "pProgram->Initialize()". I´ll explain what I´m doing right now. ... bFailed = pProgram->Initialize(); if ( bFailed ) { pErrorHandler->ReportError( __FILE__, __LINE__, "pProgram->Intialize()" ); } ... This works, but I find it inefficient to type out the whole function every time. Can you guys come up with a more efficient way to this? ---------- Mail me, Drago''s OpenGL Website

Share on other sites
What i do is define a macro such as:

#define ReportError2(lpOutputString) ReportError(__FILE__,__LINE__,lpOutputString)

if you include this in the declaration of your errorhandler class you can call it using:

...
bFailed = pProgram->Initialize();
if ( bFailed )
{
pErrorHandler->ReportError2("pProgram->Intialize()" );
}
...

===========================
No sense being pessimistic. It wouldn''''t work anyway.

Share on other sites
You can make some macros using the stringizing operator:-

#define LINE_STR1(n)  #n#define LINE_STR2(n) LINE_STR1(n)#define LINE_STRING  LINE_STR2(__LINE__) #define FILE_STRING __FILE__#define REPORT_ERROR(pObj, szText) pObj->ReportError(FILE_STRING, LINE_STRING, szText)

...Umm... I Think...

Then just type:-

REPORT_ERROR(pErrorHandler, "pProgram->Intialize()")

Pity, there''s no standard __FUNCTION__ like macro, then you could automate all of it...

As for Unreal, I think it pushes text into a buffer by throwing exceptions, because there''s a lot of ''x->y->z->u()'' text to write manually otherwise.

Jans.

Share on other sites
I actually do a form of that as well, but didn´t show it to keep the question simple.

This is what I really do:

#define M_FAILED(x) ( x < 1 )
#define M_FAIL_SAFE(f, fn, em) if ( M_FAILED( f ) ) g_pErrorHandler->ProcessError( __FILE__, __LINE__, fn, em );

M_FAIL_SAFE
(
InitializeProgram(),
"InitializeProgram()",
"Failed to initialize the program..."
);

But I doubt if this is good coding practise, but it does safe me from more mindless typing .

----------
Mail me, Drago's OpenGL Website

Edited by - drago on January 12, 2001 5:06:43 PM