SNAP Library, Developer Reference
2012-10-02 12:56:23
SNAP, a general purpose network analysis and graph mining library
|
00001 00002 // Mathmatical-Errors 00003 #if defined(__BCPLUSPLUS__) && (__BCPLUSPLUS__==0x0530) 00004 int std::_matherr(struct math_exception* e){ 00005 e->retval=0; 00006 return 1; 00007 } 00008 #elif defined(GLib_GLIBC) || defined(GLib_BSD) 00009 int _matherr(struct __exception* e){ 00010 e->retval=0; 00011 return 1; 00012 } 00013 #elif defined(GLib_SOLARIS) 00014 int _matherr(struct __math_exception* e){ 00015 e->retval=0; 00016 return 1; 00017 } 00018 #elif defined(GLib_CYGWIN) 00019 int matherr(struct __exception *e){ 00020 e->retval=0; 00021 return 1; 00022 } 00023 #elif defined(GLib_MACOSX) 00024 //int matherr(struct exception *e) { 00025 // e->retval=0; 00026 // return 1; 00027 //} 00028 #else 00029 int _matherr(struct _exception* e){ 00030 e->retval=0; 00031 return 1; 00032 } 00033 #endif 00034 00036 // Messages 00037 void WrNotify(const char* CaptionCStr, const char* NotifyCStr){ 00038 #if defined(__CONSOLE__) || defined(_CONSOLE) 00039 printf("*** %s: %s\n", CaptionCStr, NotifyCStr); 00040 #else 00041 MessageBox(NULL, NotifyCStr, CaptionCStr, MB_OK); 00042 #endif 00043 } 00044 00045 void SaveToErrLog(const char* MsgCStr){ 00046 int MxFNmLen=1000; 00047 char* FNm=new char[MxFNmLen]; if (FNm==NULL){return;} 00048 int FNmLen=GetModuleFileName(NULL, FNm, MxFNmLen); if (FNmLen==0){return;} 00049 FNm[FNmLen++]='.'; FNm[FNmLen++]='E'; FNm[FNmLen++]='r'; FNm[FNmLen++]='r'; 00050 FNm[FNmLen++]=char(0); 00051 time_t Time=time(NULL); 00052 FILE* fOut=fopen(FNm, "a+b"); if (fOut==NULL){return;} 00053 fprintf(fOut, "--------\r\n%s\r\n%s%s\r\n--------\r\n", 00054 FNm, ctime(&Time), MsgCStr); 00055 fclose(fOut); 00056 delete[] FNm; 00057 } 00058 00060 // Assertions 00061 TOnExeStop::TOnExeStopF TOnExeStop::OnExeStopF=NULL; 00062 00063 void ExeStop( 00064 const char* MsgCStr, const char* ReasonCStr, 00065 const char* CondCStr, const char* FNm, const int& LnN){ 00066 char ReasonMsgCStr[1000]; 00067 // construct reason message 00068 if (ReasonCStr==NULL){ReasonMsgCStr[0]=0;} 00069 else {sprintf(ReasonMsgCStr, " [Reason:'%s']", ReasonCStr);} 00070 // construct full message 00071 char FullMsgCStr[1000]; 00072 if (MsgCStr==NULL){ 00073 if (CondCStr==NULL){ 00074 sprintf(FullMsgCStr, "Execution stopped%s!", ReasonMsgCStr); 00075 } else { 00076 sprintf(FullMsgCStr, "Execution stopped: %s%s, file %s, line %d", 00077 CondCStr, ReasonMsgCStr, FNm, LnN); 00078 } 00079 } else { 00080 if (CondCStr==NULL){ 00081 sprintf(FullMsgCStr, "%s\nExecution stopped!", MsgCStr); 00082 } else { 00083 sprintf(FullMsgCStr, "Message: %s%s\nExecution stopped: %s, file %s, line %d", 00084 MsgCStr, ReasonMsgCStr, CondCStr, FNm, LnN); 00085 } 00086 } 00087 // report full message to log file 00088 SaveToErrLog(FullMsgCStr); 00089 // report to screen & stop execution 00090 bool Continue=false; 00091 // call handler 00092 if (TOnExeStop::IsOnExeStopF()){ 00093 Continue=!((*TOnExeStop::GetOnExeStopF())(FullMsgCStr));} 00094 if (!Continue){ 00095 ErrNotify(FullMsgCStr); 00096 #ifdef GLib_WIN32 00097 abort(); 00098 //ExitProcess(1); 00099 #else 00100 exit(1); 00101 #endif 00102 } 00103 }