Results 1 to 3 of 3

Thread: Error handling - a best way

  1. #1

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Wink Error handling - a best way

    Hi all,

    Still I'm learning C++ and I'll try my best used most better ways in my works.

    When I'm coding, I mean use of try, catch or if, else etc..., always used a single line of code. Here it is...

    Code:
    cout << "Error. GetLastError reports " << GetLastError() << endl;
    In simple word find the error code and correct way. If I'm working on MFC, cout replaced by a message box.

    My question is what is the best way to display errors for users. Displaying error codes is not prefer for users. Is that a separate section in C++, handling errors/exceptions.
    Last edited by eranga262154; Jan 17th, 2008 at 04:24 AM.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Error handling - a best way

    You can grab the error message from Windows using the FormatMessage function in conjunction with the GetLastError function..

    http://msdn2.microsoft.com/en-us/lib...82(VS.85).aspx

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: Error handling - a best way

    Thanks, seems it is fine. I can reuse it once write the code and test. I'll work it on at home and let you know if I got any issue.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width