SNAP Library, User Reference  2012-10-15 15:06:59
SNAP, a general purpose network analysis and graph mining library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
bd.cpp
Go to the documentation of this file.
00001 // #include <execinfo.h>
00002 
00004 // Mathmatical-Errors
00005 #if defined(__BCPLUSPLUS__) && (__BCPLUSPLUS__==0x0530)
00006 int std::_matherr(struct math_exception* e){
00007   e->retval=0;
00008   return 1;
00009 }
00010 #elif defined(GLib_GLIBC) || defined(GLib_BSD)
00011 int _matherr(struct __exception* e){
00012   e->retval=0;
00013   return 1;
00014 }
00015 #elif defined(GLib_SOLARIS)
00016 int _matherr(struct __math_exception* e){
00017   e->retval=0;
00018   return 1;
00019 }
00020 #elif defined(GLib_CYGWIN)
00021 int matherr(struct __exception *e){
00022   e->retval=0;
00023   return 1;
00024 }
00025 #elif defined(GLib_MACOSX)
00026 //int matherr(struct exception *e) {
00027 //  e->retval=0;
00028 //  return 1;
00029 //}
00030 #else
00031 int _matherr(struct _exception* e){
00032   e->retval=0;
00033   return 1;
00034 }
00035 #endif
00036 
00038 // Messages
00039 void WrNotify(const char* CaptionCStr, const char* NotifyCStr){
00040 #if defined(__CONSOLE__) || defined(_CONSOLE)
00041   printf("*** %s: %s\n", CaptionCStr, NotifyCStr);
00042 #else
00043   MessageBox(NULL, NotifyCStr, CaptionCStr, MB_OK);
00044 #endif
00045 }
00046 
00047 void SaveToErrLog(const char* MsgCStr){
00048   int MxFNmLen=1000;
00049   char* FNm=new char[MxFNmLen]; if (FNm==NULL){return;}
00050   int FNmLen=GetModuleFileName(NULL, FNm, MxFNmLen); if (FNmLen==0){return;}
00051   FNm[FNmLen++]='.'; FNm[FNmLen++]='E'; FNm[FNmLen++]='r'; FNm[FNmLen++]='r';
00052   FNm[FNmLen++]=char(0);
00053   time_t Time=time(NULL);
00054   FILE* fOut=fopen(FNm, "a+b"); if (fOut==NULL){return;}
00055   fprintf(fOut, "--------\r\n%s\r\n%s%s\r\n--------\r\n",
00056    FNm, ctime(&Time), MsgCStr);
00057   fclose(fOut);
00058   delete[] FNm;
00059 }
00060 
00062 // Assertions
00063 TOnExeStop::TOnExeStopF TOnExeStop::OnExeStopF=NULL;
00064 
00065 void ExeStop(
00066  const char* MsgCStr, const char* ReasonCStr,
00067  const char* CondCStr, const char* FNm, const int& LnN){
00068   char ReasonMsgCStr[1000];
00069 
00070   // stack dump, works for g++
00071   //void *array[20];
00072   //size_t size;
00073   // get the trace and print it out
00074   //size = backtrace(array, 20);
00075   //backtrace_symbols_fd(array, size, 2);
00076 
00077   // construct reason message
00078   if (ReasonCStr==NULL){ReasonMsgCStr[0]=0;}
00079   else {sprintf(ReasonMsgCStr, " [Reason:'%s']", ReasonCStr);}
00080   // construct full message
00081   char FullMsgCStr[1000];
00082   if (MsgCStr==NULL){
00083     if (CondCStr==NULL){
00084       sprintf(FullMsgCStr, "Execution stopped%s!", ReasonMsgCStr);
00085     } else {
00086       sprintf(FullMsgCStr, "Execution stopped: %s%s, file %s, line %d",
00087        CondCStr, ReasonMsgCStr, FNm, LnN);
00088     }
00089   } else {
00090     if (CondCStr==NULL){
00091       sprintf(FullMsgCStr, "%s\nExecution stopped!", MsgCStr);
00092     } else {
00093       sprintf(FullMsgCStr, "Message: %s%s\nExecution stopped: %s, file %s, line %d",
00094        MsgCStr, ReasonMsgCStr, CondCStr, FNm, LnN);
00095     }
00096   }
00097   // report full message to log file
00098   SaveToErrLog(FullMsgCStr);
00099   // report to screen & stop execution
00100   bool Continue=false;
00101   // call handler
00102   if (TOnExeStop::IsOnExeStopF()){
00103     Continue=!((*TOnExeStop::GetOnExeStopF())(FullMsgCStr));}
00104   if (!Continue){
00105     ErrNotify(FullMsgCStr);
00106 #ifdef GLib_WIN32
00107     abort();
00108     //ExitProcess(1);
00109 #else
00110     exit(1);
00111 #endif
00112   }
00113 }