Skip to main content
GameDev.net gamedev.net
🔒 Locked

Error details

Started by The C modest god Sep 24, 2005 at 1:37 AM 2 replies 650+ views
Original Post
The C modest god
The C modest god
I have seen in here the error message box. The message box says the method, line of code and file in which the error occured. How do you achieve that? Thanks in advance.
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
Ximmer
Ximmer
#define Error(message) debug_error(message, __FILE__, __LINE__)void debug_error(const char * errmsg, const char * file, int line){// Print Error Message here}
The C modest god
The C modest god
Is there no way to tell in which line and file a function is being called from within that method?
So I could get this information in one place and wont have to call __FILE__ and __LINE__ as paramters to my error method?
How did he print in which method the error occured?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
JohnBolton
JohnBolton
On some compilers there is also a __FUNCTION__ symbol that is the name of the function where it is used. So expanding on what Ximmer wrote:
    #define Error(message) debug_error(message, __FILE__, __LINE__, __FUNCTION__)    void debug_error(const char * errmsg, const char * file, int line, const char * function)    {        printf( "Error in function '%s' at line %d in '%s': %s\n",                function, line, file, errmsg };    }    void foo()    {        ...        if ( x < 0 )        {            Error( "x is less than zero" );        }        ... 
That code might print a line something like this:

Error in function 'foo' at line 345 in 'bar.c': x is less than zero
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.