[搜集]定位文件出错位置行号、日期、文件名、函数

//方法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;
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zfdc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值