try catch problem
Yesterday I posted the following, but I didn't supply the code. Here is the
problem and the code follows.
Thanks in advance for all
I use try catch mechanism and notice (in the debugger) that whenever the
control arrives to the catch section, I get an access violation (error
0xC0000005)even though it skips this section immediately.
I pass compilation without any problems and the program runs fine but
crashes every few hours.
the relevant code
// mfc_concol.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "mfc_concol.h"
#include "mfc_concolDlg.h"
#include <afxinet.h>
#include "tests.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////////////////////////////////////////////////////////////////
/
// CMfc_concolApp
BEGIN_MESSAGE_MAP(CMfc_concolApp, CWinApp)
//{{AFX_MSG_MAP(CMfc_concolApp)
// NOTE - the ClassWizard will add and remove mapping macros
here.
// DO NOT EDIT what you see in these blocks of generated
code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
////////////////////////////////////////////////////////////////////////////
/
// CMfc_concolApp construction
CMfc_concolApp::CMfc_concolApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
extern BOOL Calculate_Average(CString LastFile);
extern BOOL Calculate_Average_CFile(CString LastFile);
////////////////////////////////////////////////////////////////////////////
/
// The one and only CMfc_concolApp object
CMfc_concolApp theApp;
////////////////////////////////////////////////////////////////////////////
/
// CMfc_concolApp initialization
BOOL CMfc_concolApp::InitInstance()
{
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
/* delet dlg popup
CMfc_concolDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
*/
CString SubString;
CString curdir("C:\\");;
char CurDirectory[100];
static CString FileName, LastFile,prev_run_last_file;
CTime CreateTime, LastFileTime;
CInternetSession sess(_T("MyProgram/1.0"));
CFtpConnection* pConnect = NULL;
::GetCurrentDirectory((sizeof(CurDirectory) +1), CurDirectory);
while (1)
{
// find out the last file from the seria and bring it
//system("c:\\temp\\ActivateBringFile.bat");
try
{
// debug
if (LOCAL_DISK_FTP == 1)
pConnect =
sess.GetFtpConnection("8.30.0.165","mbt-domain\\66711","JKjk8304");
else if (LOCAL_DISK_FTP == 2)//release amsim
pConnect =
sess.GetFtpConnection("8.8.16.120","system","geler42");
else if (LOCAL_DISK_FTP == 0 || LOCAL_DISK_FTP == 3)//release
amrt2
pConnect =
sess.GetFtpConnection("8.8.16.132","system","HtggFR76");
// test local pc
//GetCurrentDirectory((sizeof(CurDirectory) +1), CurDirectory);
//BOOL res1 = pConnect->SetCurrentDirectory("..\\");
//res1 = pConnect->SetCurrentDirectory("..\\");
//res1 = pConnect->SetCurrentDirectory("..\\");
//res1 = pConnect->SetCurrentDirectory(".\????? T????\mfc_consol");
pConnect->GetCurrentDirectory(curdir);
//res1 = pConnect->SetCurrentDirectory(curdir);
// use a file find object to enumerate files
CFtpFileFind finder(pConnect);
// check if we know the last file name
//res1 = pConnect->SetCurrentDirectory("..\\");
//4-6-06 add going to the right place
BOOL res1;
if (LOCAL_DISK_FTP == 1)
res1 = pConnect->SetCurrentDirectory(".\?????
T????\mfc_consol");
else if (LOCAL_DISK_FTP == 2)//release amsim
res1 = pConnect->SetCurrentDirectory(".\?????
T????\mfc_consol");
else if (LOCAL_DISK_FTP == 3)//release amrt2
res1 =
pConnect->SetCurrentDirectory("SYS$COMMON:[SYSMGR.LESHER]");
else if (LOCAL_DISK_FTP == 0)//release amrt2
res1 =
pConnect->SetCurrentDirectory("DSA2:[USERS.GCS_DATA.TRACK.ON_LINE_MONITOR]")
;
//res1 =
pConnect->SetCurrentDirectory("SYS$COMMON:[SYSMGR.TEMP]");
//res1 = pConnect->SetCurrentDirectory("dsa2:[users_gcs_data]");
pConnect->GetCurrentDirectory(curdir);
//Last file 5-6-06
//{"AM1_MBT1_20060227_2259.MAG;1"}
// start looping
BOOL bWorking;
// if (LastFile == "")// at the beginning
// bWorking = finder.FindFile(NULL);
// else // after ther first run
// bWorking = finder.FindFile(LastFile);
bWorking = finder.FindFile(NULL);
//1BOOL bWorking = finder.FindFile("AM1_MBT1_20061205_1456.MAG");
bWorking = finder.FindNextFile();
//CString BeforeLastFile = (LPCTSTR) finder.GetFileURL());
//LastFile = finder.GetFileName();
//LastFile = "AM1_MBT1_20060000_0000.MAG";
LastFile = "AM1_MBT1_20063131_0000.MAG";
//CString monthstring, datestring
while (bWorking)
{
// LastFile = "AM1_MBT1_20063131_0000.MAG";
FileName = finder.GetFileName();
//GetCurrentDirectory((sizeof(CurDirectory) +1),
CurDirectory);
//SetCurrentDirectory(CurDirectory);
// TEST
//FileName = "AM1_MBT1_20061205_1456.MAG";
SubString = FileName.Left(9);
if(FileName.Left(9) == "AM1_MBT1_")
{
CString monthstring = FileName.Mid(13,2);
int month = atoi(monthstring);
//if (month >= atoi(LastFile.Mid(13,2)))
if (month <= atoi(LastFile.Mid(13,2)))
{
if (month < atoi(LastFile.Mid(13,2)))
LastFile = FileName;
//continue;
// check date
CString datestring = FileName.Mid(15,2);
int date = atoi(datestring);
//if (date >= atoi(LastFile.Mid(15,2)))
if (date <= atoi(LastFile.Mid(15,2)))
{
if (date < atoi(LastFile.Mid(15,2)))
LastFile = FileName;
//continue;
// check hour
CString hourstring = FileName.Mid(18,2);
int hour = atoi(hourstring);
//if (hour >= atoi(LastFile.Mid(18,2)))
if (hour <= atoi(LastFile.Mid(18,2)))
{
if (hour < atoi(LastFile.Mid(18,2)))
LastFile = FileName;
//continue;
// check minutes
CString minuitstring =
FileName.Mid(20,2);
int minuit = atoi(minuitstring);
//if (minuit >=
atoi(LastFile.Mid(20,2)))
if (minuit <= atoi(LastFile.Mid(20,2)))
{
LastFile = FileName;
//Bring the file to the PC
if (LOCAL_DISK_FTP == 0 || LOCAL_DISK_FTP == 3)// only in debug
BOOL res = pConnect->GetFile(LastFile,LastFile,
TRUE,FILE_ATTRIBUTE_ARCHIVE,
INTERNET_FLAG_TRANSFER_ASCII,
1);
//open file and read lines 10-16
//4-7-06 remove file at source
BOOL res = pConnect->Remove(LastFile);
//Calculate_Average(LastFile);
if ( prev_run_last_file != LastFile ) // calculate only if new file
Calculate_Average_CFile(LastFile);
prev_run_last_file = LastFile; // calculate only if new file
DeleteFile(LastFile);
LastFile = "AM1_MBT1_20063131_0000.MAG";
}
}
}
}
}
bWorking = finder.FindNextFile();
//CString LastFile = (LPCTSTR) finder.GetFileURL());
}// while (working)
/*
//Bring the file to the PC
if (LOCAL_DISK_FTP == 0 || LOCAL_DISK_FTP == 3)// only in debug
BOOL res = pConnect->GetFile(LastFile,LastFile,
TRUE,FILE_ATTRIBUTE_ARCHIVE,
INTERNET_FLAG_TRANSFER_ASCII,
1);
//open file and read lines 10-16
//4-7-06 remove file at source
BOOL res = pConnect->Remove(LastFile);
//release
//Calculate_Average(LastFile);
if ( prev_run_last_file != LastFile ) // calculate only if new file
Calculate_Average_CFile(LastFile);
prev_run_last_file = LastFile; // calculate only if new file
//BOOL res = pConnect->Remove(LastFile);
*/
pConnect->Close();
}// try
//read lines 10 - 16
catch (CInternetException* pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz, 1024);
printf("ERROR! %s\n", sz);
pEx->Delete();
}
// sleep 20 minuits
if (LOCAL_DISK_FTP == 0)
Sleep(20*60*1000);
else if (LOCAL_DISK_FTP == 3)
Sleep(20*60*10);
}// while (1)
// open file GCS$DATA:[TRACK.MEASR]AM1_MBT1_2006014_1240.MAG
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}