473,378 Members | 1,580 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Failure in file creation and exception raised

Dear All

Hello
I am Saeed Amrollahi.
I encountered a very strange bug in my program. The problem is:
the program reads a formatted text file of trade summary in Tehran
Stock Exchange organization. In each line there are same fields like
Date (YYYYMMDD) Ticker Symbol Vol of Share Price ...
Based on date, I should check is there the file with the full path:
<Drive Letter>\StockExchangeDataCenter\TradeSummary\YYYY\ MM\DD
if the file exists, I should append the line to the file and if there
isn't a file with above path, the program creates an empty file in
suitable path. An exception raised when
program want to create an empty file.
I am sure the path is correct, but I think Windows are sensible about
the depth of path. another part of program uses the following path:
<Drive Letter>\StockExchangeDataCenter\TradeSummary\YYYY
and it is OK!
I know my question may be an Off topic one, but please help me.
my code is here (the unrelated details were excluded):

void CAS400SysTrdSummaryInsDialog::InsRec(const string& s) // insert
string into data center's file
{
string ye;
ye = "2006";
string mo;
mo = "11";
string da;
da = "12";
// create correct path
map<string, stringm = g_DataCenterManager;
string PathName = DataCenterManager::DataCenterPath +
m["TRD_SUMMARY_CAT"] + m["AS400_DATA_SOURCE"] + ye + "mo + da +
".WIN";
CFileFind Finder;
BOOL b = Finder.FindFile(PathName.c_str());
if (!b) { // a file with <Year>.WIN should be created
AS400OutFile f(PathName); // <----- Exception raised!!!

try {
if (!f)
throw FileIsNotCreated();
}

catch(const FileIsNotCreated&) {

}

f.Close(); // closing file
/* ... */
}

else { // the file already have been created
AS400OutFile f(PathName, AS400OutFile::APPEND);
/* ... */
}
}
class AS400OutFile {
public:
enum OPEN_MODE { OUTPUT, APPEND };
AS400OutFile(std::string&, OPEN_MODE = OUTPUT); // use it for
creating and opening a file (for wrting into an AS/400 source file)
void Open(std::string&, OPEN_MODE = OUTPUT);
void Close();
~AS400OutFile();
// ...
private:
std::string PathName; // full pathname
std::ofstream f; // stream file
};

inline AS400OutFile::AS400OutFile(std::string& PathName_, OPEN_MODE
m) :
PathName(PathName_)
{
if (m == OUTPUT)
f.open(PathName.c_str(), ios_base::out); // open for write
else
f.open(PathName.c_str(), ios_base::app); // open for append

if (!f)
throw FileIsNotCreated(PathName);
}

As a final word, I learned from chapter 34 of C++ FAQ Lite:
Miscellaneous technical issues: "You should use forward slashes ("/")
rather than backslashes ("\") in your
#include filenames, even on an operating system that uses backslashes
such as DOS, Windows".
I use Visual C++ 6.0 under Windows XP.

Regards

Apr 15 '07 #1
1 2227

<s_*********@yahoo.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
Dear All

Hello
I am Saeed Amrollahi.
I encountered a very strange bug in my program. The problem is:
the program reads a formatted text file of trade summary in Tehran
Stock Exchange organization. In each line there are same fields like
Date (YYYYMMDD) Ticker Symbol Vol of Share Price ...
Based on date, I should check is there the file with the full path:
<Drive Letter>\StockExchangeDataCenter\TradeSummary\YYYY\ MM\DD
if the file exists, I should append the line to the file and if there
isn't a file with above path, the program creates an empty file in
suitable path. An exception raised when
program want to create an empty file.
I am sure the path is correct, but I think Windows are sensible about
the depth of path. another part of program uses the following path:
<Drive Letter>\StockExchangeDataCenter\TradeSummary\YYYY
and it is OK!
I know my question may be an Off topic one, but please help me.
my code is here (the unrelated details were excluded):
Perhaps the directory does not exist? You can't create a file in a
directory unless the directory has been created first. (And for information
on creating directories, you need to ask on a Windows newsgroup.)

-Howard

Apr 16 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Hans-Joachim Widmaier | last post by:
Recently, there was mentioned how someone who had understood Python's error handling would write the "open and read file with error handling" idiom. If I remember correctly, it went like this: ...
9
by: Jon Perez | last post by:
I have a C extension function into which I pass a list of lists of tuples: , , , ] I then unpack the values (down to the tuple elements) into their C values using:
8
by: StepH | last post by:
Hi, I've this module : from optparse import OptionParser import re _version = "P1" def writeVar(f, line):
5
by: juergen perlinger | last post by:
Hello out there. sometimes I need to have proper control of the floating point arithmetic of the C(and C++) runtime system, and using the f.p. exception handling of the C99 standard is quite...
44
by: petermichaux | last post by:
Hi, I have been using the following line of code to create an object called "Serious" if it doesn't already exist. if (Serious == null) {var Serious = {};} This works in the scripts I use...
1
by: Bob | last post by:
In Vs 2005 you have new applicationsEvents.vb I was testing it in a simple app and found that it was easier to implement unhandled exception management tah it was in Vs2003 (vb.net) You can, if you...
0
by: Marty Cruise | last post by:
I successfully deploy my application to 20 domain users. Only one new user is giving me a problem, although he can access all domain resources. When he clicks the installation link on the...
132
by: Zorro | last post by:
The simplicity of stack unraveling of C++ is not without defective consequences. The following article points to C++ examples showing the defects. An engineer aware of defects can avoid...
5
by: =?Utf-8?B?c3VydHVyeg==?= | last post by:
Hi, I feel like a noob for asking this. When I publish a VB windows application, I want to disable the ability of the the user to continue when there is an unhandled exception. For example,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.