Rate My Application: File Exception Handling

This is a discussion on Rate My Application: File Exception Handling within the C++ Programming forums, part of the General Programming Boards category; Hello. I recently learned about the try, throw and catch methods so I decided to combine that recently retrieved knowledge ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    71

    Rate My Application: File Exception Handling

    Hello. I recently learned about the try, throw and catch methods so I decided to combine that recently retrieved knowledge with my knowldge of file streaming(ifstream, ofstream, fstream). I made two different versions of the application and they both work perfectly on Windows XP.

    The first one is just a regular console. While the second one is a console along with a pop-up window dialogue(WinAPI: MessageBox( HWND, char*, char*, unsigned short int ) ).

    Note: My prototype for the MessageBox function maybe off but who cares. It's been years since I programmed in Win32/WinAPI.
    Attached Files Attached Files
    Name: Eric Lesnar
    Learning: C/C++, SDL, WinAPI, OpenGL, and Python
    Compiler: Dev-C++ 4.9.0
    Current Game Project: Acoznict

  2. #2
    Registered User
    Join Date
    Sep 2003
    Posts
    71
    The second one. It's exactly identical, its just that the application reads the data from the .txt file and then displays it's content in a dialogue box.
    Attached Files Attached Files
    Name: Eric Lesnar
    Learning: C/C++, SDL, WinAPI, OpenGL, and Python
    Compiler: Dev-C++ 4.9.0
    Current Game Project: Acoznict

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    1) Very few people will take the time to download your code, review it, and post back here. Paste code in your post and you may get better results.

    2) Code reviews are two-way. I haven't gotten feedback from the review I gave you of your previous program, why should I waste my time sending another review to the bit bucket? It may have helped you, you may not have read it...I just don't know.

    So your first order of business is to be more considerate to the people you are asking to review your code. A good review takes time and effort and we don't have to do it, remember that.
    My best code is written with the delete key.

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Both files
    First thing: lack of comments.

    Code:
         using namespace std;
         using std::ifstream;
    This is a wee bit redundant.

    Code:
         FileException( std::string error, std::string file ):
                      strErrMsg(error), strFilename(file) {}
                      
         std::string strErrMsg;
         std::string strFilename;
    You are 'using namespace std', and you are still referencing the string class with the std:: prefix? Tsk, tsk, tsk.

    Code:
    int main( )
    int main( void )
    This way you are explicitly stating that there are no arguments that can be passed to main.

    Code:
         return EXIT_SUCCESS;
    Not necessary. A return value on success in C++ is not required.



    From the 1st file:
    Code:
    cout << strName.c_str() << '\n';
    The ofstream class is capable of handling STL strings, so you don't need the c_str( ) call.



    From the 2nd file:
    Code:
            std::string strFile= "Name.txt";
            ifstream fin( strFile.c_str() );
    Redundant. Just use ifstream fin( "Name.txt" );
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Registered User
    Join Date
    Sep 2003
    Posts
    135
    Originally posted by XSquared
    Code:
    int main( )
    int main( void )
    This way you are explicitly stating that there are no arguments that can be passed to main.
    You're thinking of C. In C++ int main() is explicit. The (void) is just as redundant as the other redundant items you mention elsewhere in your post.

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >>You're thinking of C. In C++ int main() is explicit.
    Thanks for pointing that out. I forgot that it was C-only.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. Invoking MSWord
    By Donn in forum C Programming
    Replies: 21
    Last Post: 09-08-2001, 04:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21