Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

Oerror.cpp Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Oerror.cpp

Go to the documentation of this file.
00001 //Filename    : OERR.CPP
00002 //Description : Object Error Handling
00003 
00004 #include <new.h>
00005 #include <stdlib.h>
00006 #include <stdio.h>
00007 #include <stdarg.h>
00008 #include <windows.h>
00009 
00010 #include <OSYS.H>
00011 //#include <OBOX.H>
00012 #include <OVGA.H>
00013 #include <OVGALOCK.H>
00014 #include <ALL.H>                                  // class Error is declared here
00015 
00016 //------------------------------------------------//
00017 //
00018 // There are several types of errors :
00019 //
00020 // 1. Internal Errors caused by bugs of the program
00021 // 2. Runtime Errors caused by using up of resources (memory) or
00022 //    unexpected environment errors. (disk error)
00023 //
00024 //------------------------------------------------//
00025 
00026 static int new_func_handler(size_t);
00027 static void error_quit_game(char *msg);
00028 
00029 //---------- define static variable ----------//
00030 
00031 static char error_flag=0;                         // prevent error message dead loop
00032 
00033 //------- Begin of function new_func_handler ------------//
00035 static int new_func_handler(size_t allocSize) {
00036     err.mem();
00037 
00038     return 0;
00039 }
00040 
00041 //-------- End of function new_func_handler --------------//
00042 
00043 //------- Begin of function error_quit_game ------------//
00044 static void error_quit_game(char *msg) {
00045     //if( vga.is_inited() )
00046     //  box.msg( strBuf, 0 );
00047 
00048     if( vga_front.dd_buf ) {
00049         VgaFrontLock vgaLock;
00050 
00051         ShowCursor(TRUE);
00052         MessageBox(sys.main_hwnd, msg, WIN_TITLE, MB_OK | MB_ICONERROR);
00053         ShowCursor(FALSE);
00054     }
00055     else {
00056         ShowCursor(TRUE);
00057         MessageBox(sys.main_hwnd, msg, WIN_TITLE, MB_OK | MB_ICONERROR);
00058         ShowCursor(FALSE);
00059     }
00060 
00061     sys.deinit_directx();
00062 }
00063 
00064 //------- End of function error_quit_game ------------//
00065 
00066 //------- Begin of function Error::Error ------------//
00071 Error::Error() {
00072     _set_new_handler(new_func_handler);             // set_new_handler() is a C++ function
00073     // ##### begin Gilbert 26/04/2001 #######//
00074     _set_new_mode(1);                               // malloc also call new_func_handler on error, useful for NO_MEM_CLASS
00075     // ##### end Gilbert 26/04/2001 #######//
00076 
00077     extra_handler = NULL;
00078 }
00079 
00080 //-------- End of function Error::Error --------------//
00081 
00082 //------- BEGIN OF FUNCTION Error::internal -----------//
00083 //
00084 // sample error message :
00085 //
00086 // Exit : Insufficient Memory
00087 // File : ODYNARR.CPP
00088 // Line : 453
00089 //
00090 // Continue ?
00091 //
00092 // <char*> errMsg   - the error message
00093 // <char*> fileName - the file name of the CPP function cause error
00094 //                    usually is __FILE__
00095 // <int>   lineNum  - the line number of program cause error
00096 //                    usually is __LINE__
00097 //
00098 void Error::internal(char* errMsg,char* fileName,int lineNum) {
00099     if( error_flag )                                // prevent error message dead loop
00100         return;
00101 
00102     error_flag=1;
00103 
00104     //-------------------------------------------------//
00105 
00106     char strBuf[100];
00107 
00108     if( extra_handler )                             // all the extra error handler first
00109         (*extra_handler)();
00110 
00111     if( errMsg )
00112         sprintf(strBuf, "Error : %s\nFile : %s\nLine : %d\n", errMsg,fileName,lineNum );
00113     else
00114         sprintf(strBuf, "Error on File : %s\nLine : %d\n",fileName,lineNum );
00115 
00116     //-------- display error message -------//
00117     OutputDebugString( strBuf );
00118 
00119     error_quit_game(strBuf);
00120     exit( -2 );
00121 }
00122 
00123 //--------- END OF FUNCTION Error::internal ----------//
00124 
00125 //------- BEGIN OF FUNCTION Error::mem -----------//
00126 //
00127 // There is no memory left to save the screen, so don't use v_pop.ask(),
00128 // direct output to screen.
00129 //
00130 void Error::mem() {
00131     if( error_flag )                                // prevent error message dead loop
00132         return;
00133 
00134     error_flag=1;
00135 
00136     //-------------------------------------------------//
00137 
00138     if( extra_handler )
00139         (*extra_handler)();
00140 
00141     char* strBuf = "Insufficient Memory, execution interrupt.";
00142 
00143     //-------- display error message -------//
00144 
00145     OutputDebugString( strBuf );
00146     error_quit_game(strBuf);
00147     exit( -2 );
00148 }
00149 
00150 //--------- END OF FUNCTION Error::mem ----------//
00151 
00152 //------- BEGIN OF FUNCTION Error::msg -----------//
00153 //
00154 // <char*> formated erorr message with % argument
00155 // <....>  the argument list
00156 //
00157 void Error::msg( char *format, ... ) {
00158     if( error_flag )                                // prevent error message dead loop
00159         return;
00160 
00161     error_flag=1;
00162 
00163     //-------------------------------------------------//
00164 
00165     //---- translate the message and the arguments into one message ----//
00166 
00167     char strBuf[100];
00168 
00169     va_list argPtr;                                 // the argument list structure
00170 
00171     va_start( argPtr, format );
00172     vsprintf( strBuf, format, argPtr );
00173 
00174     va_end( argPtr );
00175 
00176     //-------- display error message -------//
00177 
00178     OutputDebugString( strBuf );
00179     error_quit_game(strBuf);
00180     error_flag = 0;                                 // this error does not exit program
00181 }
00182 
00183 //--------- END OF FUNCTION Error::msg ----------//
00184 
00185 //------- BEGIN OF FUNCTION Error::run --------//
00186 //
00187 // <char*> formated erorr message with % argument
00188 // <....>  the argument list
00189 //
00190 void Error::run( char *format, ... ) {
00191     if( error_flag )                                // prevent error message dead loop
00192         return;
00193 
00194     error_flag=1;
00195 
00196     //-------------------------------------------------//
00197 
00198     if( extra_handler )
00199         (*extra_handler)();
00200 
00201     //---- translate the message and the arguments into one message ----//
00202 
00203     char strBuf[100];
00204 
00205     va_list argPtr;                                 // the argument list structure
00206 
00207     va_start( argPtr, format );
00208     vsprintf( strBuf, format, argPtr );
00209 
00210     va_end( argPtr );
00211 
00212     //-------- display error message -------//
00213 
00214     OutputDebugString( strBuf );
00215     error_quit_game(strBuf);
00216     exit( -2 );
00217 }
00218 
00219 //---------- END OF FUNCTION Error::run -----------//

Generated on Fri Aug 23 01:37:28 2002 for VirtualU by doxygen1.2.17