//方法1
// ************************************************
//
// Global.h // define functions
//
// ************************************************
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <atltime.h>
#pragma warning(disable : 4996)
using namespace std;
//
// output log file
void LogStr(const string & str)
{
time_t ltime;
char buf[26];
time( <ime );
ctime_s(buf, 26, <ime );
stringstream ss;
string str1 = ">>>>\n";
ss<<"\n"<<buf<<">>>>"<<"\n"<<str<<"\n";
// Write string to a log file
string FileName("LogFile.txt");
ofstream out;
out.open(FileName.c_str(), ios::app);
out<<ss.str();
out.close();
}
//
//out put exception message
#define ExceptionLog(strE) \
{\
stringstream ss;\
ss << "Error: " << __FILE__ << "\nLine: " << __LINE__ << "=n" << "Message: " << strE << "\n";\
LogStr(ss.str());\
}
//方法2
#ifndef _GOLD_DEBUG_H
#define _GOLD_DEBUG_H
#ifdef __cplusplus
#if __cplusplus
extern "C"{
#endif
#endif /* __cplusplus */
//#define GI_DEBUG
#ifdef GI_DEBUG
#define GI_DEBUG_POINT() printf("\n\n[File:%s Line:%d] Fun:%s\n\n", __FILE__, __LINE__, __FUNCTION__)
#define dbg_printf(arg...) printf(arg);
#define GI_ASSERT(expr) \
do{ \
if (!(expr)) { \
printf("\nASSERT failed at:\n >File name: %s\n >Function : %s\n >Line No. : %d\n >Condition: %s\n", \
__FILE__,__FUNCTION__, __LINE__, #expr);\
} \
}while(0);
/*调试宏, 用于暂停*/
#define GI_DEBUG_PAUSE() \
do \
{ \
GI_DEBUG_POINT(); \
printf("pause for debug, press 'q' to exit!\n"); \
char c; \
while( ( c = getchar() ) ) \
{ \
if('q' == c) \
{ \
getchar(); \
break; \
} \
} \
}while(0);
#define GI_DEBUG_PAUSE_ARG(arg...) \
do \
{ \
printf(arg); \
GI_DEBUG_PAUSE() \
}while(0);
#define GI_DEBUG_ASSERT(expression) \
if(!(expression)) \
{ \
printf("[ASSERT],%s,%s:%d\n", __FILE__, __FUNCTION__, __LINE__);\
exit(-1); \
}
#else
#define GI_ASSERT(expr)
#define GI_DEBUG_PAUSE()
#define GI_DEBUG_PAUSE_ARG(arg)
#define GI_DEBUG_POINT()
#define dbg_printf(arg)
#define GI_DEBUG_ASSERT(expression)
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif
//后来自己修改
#ifndef _GOLD_DEBUG_H
#define _GOLD_DEBUG_H
#ifdef __cplusplus
#if __cplusplus
extern "C"{
#endif
#endif /* __cplusplus */
//#define GI_DEBUG
#ifdef GI_DEBUG
#define GI_DEBUG_POINT() printf("\n\n[File:%s Line:%d] Fun:%s\n\n", __FILE__, __LINE__, __FUNCTION__)
#define dbg_printf(arg...) printf(arg);
#define GI_ASSERT(expr) \
do{ \
if (!(expr)) { \
printf("\nASSERT failed at:\n >File name: %s\n >Function : %s\n >Line No. : %d\n >Condition: %s\n", \
__FILE__,__FUNCTION__, __LINE__, #expr);\
} \
}while(0);
/*调试宏, 用于暂停*/
#define GI_DEBUG_PAUSE() \
do \
{ \
GI_DEBUG_POINT(); \
printf("pause for debug, press 'q' to exit!\n"); \
char c; \
while( ( c = getchar() ) ) \
{ \
if('q' == c) \
{ \
getchar(); \
break; \
} \
} \
}while(0);
#define GI_DEBUG_PAUSE_ARG(arg...) \
do \
{ \
printf(arg); \
GI_DEBUG_PAUSE() \
}while(0);
#define GI_DEBUG_ASSERT(expression) \
if(!(expression)) \
{ \
printf("[ASSERT],%s,%s:%d\n", __FILE__, __FUNCTION__, __LINE__);\
exit(-1); \
}
#else
#define GI_ASSERT(expr)
#define GI_DEBUG_PAUSE()
#define GI_DEBUG_PAUSE_ARG(arg)
#define GI_DEBUG_POINT()
#define dbg_printf(arg)
#define GI_DEBUG_ASSERT(expression)
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif
//主体程序
//#include "stdafx.h"
#include "global.h"
//#include "g2.h"
#include "g3.h"
int _tmain(int argc, _TCHAR* argv[])
{
int xcN = 2;
int ycN = 3;
ExceptionLog("1");
int **candiPixel = new int*[xcN];
for (int i=0; i<xcN; i++)
{
candiPixel[i] = new int[ycN];
for (int j=0; j<ycN; j++)
{
candiPixel[i][j] = 0;
}
}
GI_DEBUG_POINT();
ExceptionLog("2");
try
{
throw 10;
for (int i=0; i<xcN; i++)
{
for (int j=0; j<ycN; j++)
{
cout<<i<<"\t"<<j<<"\t"<<candiPixel[i][j]<<endl;
}
}
for (int i=0; i<xcN; i++)
{
delete [] candiPixel[i];
candiPixel[i] = NULL;
}
delete [] candiPixel;
}
catch (int e)
{
cout<<e<<endl;
for (int i=0; i<xcN; i++)
{
delete [] candiPixel[i];
candiPixel[i] = NULL;
}
delete [] candiPixel;
string str("Throw 10"); // output the error message
ExceptionLog(str);
}
return 0;
}