home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-09-29 | 1.9 KB | 85 lines | [TEXT/KAHL] |
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
-
- #if defined( macintosh) || defined( __MWERKS__)
-
- #else
- #include <strstream.h>
- #endif
-
- #include <new.h>
-
- #ifdef macintosh
- #ifdef __SC__
- #include <Pascal.h>
- #endif
- #endif
-
- #include "general.h"
-
- int general::new_handler_installed = 0;
-
- void CheckForError( const int errorno, const char *text)
- {
- if( errorno != 0)
- {
- #if defined( macintosh) || defined( __MWERKS__)
- char buffer[ 256];
- sprintf( buffer, "CheckForError: %ld ", errorno);
- strcat( buffer, text);
- CtoPstr( buffer);
- DebugStr( (unsigned char *)buffer);
- #else
- //
- // We want to call 'cout.operator<<' only one time since it puts up an alert if
- // we are running in an application and we only want one such an alert.
- // ('Warning: writing to standard output is not allowed' or something like that)
- // (940728: taking this out of the Mac builds, but keeping this proviso in)
- //
- ostrstream tempstream;
- tempstream << "unrecoverable error: " << text << ", error# " << errorno << "\n";
-
- tempstream << ends;
-
- char *destring = tempstream.str();
-
- cerr << destring;
-
- delete destring;
- #endif
- exit( EXIT_FAILURE);
- }
- }
-
- general::general()
- {
- if( !new_handler_installed)
- {
- set_new_handler( &report_out_of_memory_and_exit);
- new_handler_installed = true;
- }
- }
-
- void report_error_and_exit( const char *message)
- {
- #if defined( macintosh) || defined( __MWERKS__)
- //
- // Note: c2pstr _does_ modify message, but we are going to exit
- // _real_soon_now_, so this will not be a big problem…
- // 941208: Actually, it may be a problem (e.g. when message is inside
- // a resource, in ROM, or the like)
- //
- CtoPstr( (char *)message);
- DebugStr( (unsigned char *)message);
- #else
- cerr << message << flush;
- #endif
- exit( EXIT_FAILURE);
- }
-
- void report_out_of_memory_and_exit()
- {
- report_error_and_exit( "operator new failed: out of memory. Exiting...\n");
- }
-