如题:
try
{
}
catch (CMemoryException* e)
{
MessageBox()
}
catch (CFileException* e)
{
}
catch (CException* e)
{
}想用MessageBox()把异常的详细信息输出来,该如何写?谢谢关注!
try
{
}
catch (CMemoryException* e)
{
MessageBox()
}
catch (CFileException* e)
{
}
catch (CException* e)
{
}想用MessageBox()把异常的详细信息输出来,该如何写?谢谢关注!
或者AfxMessageBox();弹出提示;这两个函数的参数为CString对象,你可以定义一个,然后用CString的Format函数把错误信息转换为CString,然后输出。
long DBConnect::ConnectSQL(_ConnectionPtr &connect,CString dbName,CString userName,CString pwd,CString dbAddr,long lOption)
{
CoInitialize(NULL); //初始化Com组件 不知是否有必要
connect.CreateInstance(__uuidof(Connection)); //Connection用于与数据库服务器的链接
CString conStr; //数据库连接字符串
conStr.Format(_T("Driver=SQL SERVER;Database=%s;Server=%s; UID=%s;PWD=%s;"),dbName,dbAddr,userName,pwd);
/******************连接数据库********************/
try
{
connect->ConnectionTimeout = 5; //设置连接时间
connect->Open(_bstr_t(conStr),"","",lOption); //连接SQL SERVER
}
catch(_com_error e) //捕捉异常
{
AfxMessageBox(e.ErrorMessage());
//或AfxMessageBox(e.Description());
return -5;
}
CoUninitialize(); //释放com组件//不知是否有必要
return 1;
}
{
AfxMessageBox(e.ErrorMessage());
//或AfxMessageBox(e.Description());
return -5;
}
你要的答案!