Error handling and debugging

Hmm this is an important topic hey… And can save you a lot of pain…

So what method do you use ???

Here’s what mine look like
http://www.ompac.net.au/~troyfa/exception.jpg

Yeah it tells you where the error is, how it happened, what line, and what module it’s in… I created this demo in about 1/2 hour, just playing around…

you can download that demo ( 500KB ), which expands to 1MB… Why so big ??? Yeah i packed some cool stuff in there… “Use the force Luke”… Run it several times, and while running different programs, some of the data changes too…

the demo is here
http://www.ompac.net.au/~troyfa/Exception.zip

NOTE: When you press each button on the demo, it will try to crash… But the error handling stuff kicks in and stops it, thus analizing the code, and making a report…

Heres some interesting stuff…

When you create an instance of a class, a new array of char, etc, anything via the new command… If you are running low on memory, and it failed, what does it do ?? and how do you overide it ???

ANSWER:

This is what i use… It’s also in my openGL windows toolkit…

#include <windows.h>
#include <new.h> /* Need this header /
#include <stdlib.h> /
Abort() /
//-------------------------------------
/
Make our special Exception class /
class ELowMemory : public std::bad_alloc
{
protected:
char
FMessage;
public:
ELowMemory( char* message ) _RWSTD_THROW_SPEC_NULL : std::bad_alloc( )
{ FMessage = message; }
ELowMemory( const &ELowMemory& ) _RWSTD_THROW_SPEC_NULL : std::bad_alloc( ){ ; }
ELowMemory& operator=( const ELowMemory& ) _RWSTD_THROW_SPEC_NULL { return this; }
virtual ~ELowError( ) _RWSTD_THROW_SPEC_NULL { }
inline char
Message( void )const{ return FMessage; }
};
//------------------------------------------
/* Make this global - it stays in memory all the time

  • We do this now, so that when we are running
  • Low on memory, we will not be able to create it then
    /
    ELowMemory ERROR_LOW_MEMORY( “System is running low on resources.
    It’s time to Re-Boot your compter
    \0” );
    //------------------------------------------
    /
    Our custom made - bad_alloc handler routine
    /
    void LowMemoryError( void )
    {
    /
    We now have no memory left - so display message and bail out /
    /
    Do not use MessageBox!!! We have no mem /
    /
    We must have a dialogbox already made, and in memory /
    /
    We just need to display it /
    Display( ERROR_LOW_MEMORY ); /
    This is a custom made function /
    abort(); /
    Pull the rungs out of the program /
    /
    Note - at this stage, your program may not stut down normally /
    /
    So exit now !!! /
    }
    //------------------------------------------
    int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR CmdLine, int CmdShow )
    {
    set_new_handler( LowMemoryError );/
    Our bad_alloc overide /
    .
    .
    .
    /
    --------->>>> Rest of windows ---------->>> */
    }

I hope that maybe usefull to anyone here…

Anybody else got some good things ???