|
-
Jan 17th, 2008, 04:21 AM
#1
Thread Starter
PowerPoster
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
-
Jan 17th, 2008, 05:02 AM
#2
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
-
Jan 17th, 2008, 05:23 AM
#3
Thread Starter
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|