NTexception.cxx

Go to the documentation of this file.
00001 //
00002 // This module is included to suppress NT's annoying behaviour of
00003 // popping up an 'unhandled exception' dialog box whenever a segment
00004 // violation occurs -- or other special errors that occur only on nt.
00005 //
00006 // When used, this object module MUST BE FIRST in your link order!
00007 //
00008 
00018 
00019 
00020 #ifndef _MSC_VER
00021 namespace IGNORE_THIS_FREAKING_NAMESPACE_DARNIT 
00022 {
00023   static int trashola=1;  // if not on NT, ignore this object module
00024   void doit()
00025   {
00026     trashola=2;
00027   }
00028 };
00029 #else
00030 
00031 // This stuff superseeds the default OS exception handler -- when exceptions
00032 // occur, the program dies WITHOUT putting up a dialog box.  This must be
00033 // the first object module linked into your executable to ensure that static
00034 // initializations that cause errors do not pop up annoying dialog boxes that
00035 // hang build scripts -- instead they merely crash producing error messages.
00036 //
00037 // Note that if this module is not linked first, it will still work -- but
00038 // will not protect object modules linked earlier!  It really should be first.
00039 
00040 
00041 #include <windows.h>
00042 #include <portable_io.h>
00043 #include <stdlib.h>
00044                               
00045 namespace
00048 {
00049   LONG WINAPI death_by_exception(_EXCEPTION_POINTERS *ExceptionInfo)
00050   {
00053 
00054 
00055     fprintf(stderr, "\n\n\nSegfault or other major exception has occurred\n\n\n");
00056     fflush(stderr);
00057     exit(1);
00058     return 0;
00059   }
00060   
00061   struct ForceStaticInvocation
00064   {
00065     ForceStaticInvocation() 
00066     {
00067       SetUnhandledExceptionFilter(death_by_exception);
00068     }
00069   };
00070   
00071   ForceStaticInvocation exceptionHandlerInstaller; 
00072 };
00073 #endif
00074 
00075 /*
00076   This is the test program for the above
00077 
00078 int main()
00079 {
00080   double *d = (double*)0x1;
00081 
00082   *d = 1.0;
00083 }
00084 
00085 */
00086 
Generated on Wed Feb 29 22:50:05 2012 for CXXUtilities by  doxygen 1.6.3