Failure in file creation and exception raised

Discussion in 'C++' started by s_amrollahi@yahoo.com, Apr 15, 2007.

  1. Guest

    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, string> m = 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::eek:fstream f; // stream file
    };

    inline AS400OutFile::AS400OutFile(std::string& PathName_, OPEN_MODE
    m) :
    PathName(PathName_)
    {
    if (m == OUTPUT)
    f.open(PathName.c_str(), ios_base::eek:ut); // 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, 2007
    #1
    1. Advertising

  2. Howard Guest

    <> wrote in message
    news:...
    > 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
    Howard, Apr 16, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Carlos
    Replies:
    1
    Views:
    353
    Wilco Bauwer
    Feb 17, 2005
  2. =?Utf-8?B?SklNLkgu?=

    : an exception raised

    =?Utf-8?B?SklNLkgu?=, Mar 2, 2005, in forum: ASP .Net
    Replies:
    9
    Views:
    422
    =?Utf-8?B?SGl0ZXNo?=
    Jun 3, 2005
  3. Lonnie Princehouse
    Replies:
    8
    Views:
    525
    Lonnie Princehouse
    Oct 2, 2004
  4. Replies:
    0
    Views:
    930
  5. friend
    Replies:
    1
    Views:
    197
    Thomas 'PointedEars' Lahn
    May 12, 2008
Loading...

Share This Page