Click to See Complete Forum and Search --> : Errror handling


Sophie
April 16th, 1999, 09:15 AM
Hi,

I'm trying to capture my errors and I'm finding it hard to use the resource Id in order to be able to translate my application quick and easy.

How would I do this?

if(sf.Open( O_RDONLY) == FALSE){
int errorCode = sf.LastError();
SysErrString errStr(errorCode);
int iResponse = AfxMessageBox(errStr, MB_YESNO|MB_ICONERROR);
}

This will give me an error "The system cannot find the file specified"
I need to specify which file I'm talking about. I found this function AfxFormatString1 or AfxFormatString2. How can I use this to implement:
"Could not open the file 1%" would this be what I write in IDS_ERROR.

How do I get 1% to be the sf? And how do I pass the system error "errStr"

Thanks, If i'm confusing you please asked me again. I'm a little confused on how this is done

Michael Decker
April 16th, 1999, 11:47 AM
Yes, in the string table you would have something like: "Cannot not open the file: %1"

In your source code you would have:
CString strMsg;
AfxFormatString1(strMsg, IDS_ERROR, strFilename);
int iResponse = AfxMessageBox(strMsg, MB_YESNO|MB_ICONERROR);

Hope this helps!
Michael...

ValerieB
April 16th, 1999, 12:03 PM
Michael's post is absolutely correct, however I have a different way to solve your problem. Since you are never sure if the error will always be "The system cannot find the file specified", you want to continue using the code you have below. To include the name of the file, I would suggest the following modification:

(Let's assume szFilename is the name of the file you're opening.)

if (FALSE == sf.Open(O_RDONLY))
{
int errorCode = sf.LastError();
SysErrString errStr(errorCode);
CString szErrStr;
szErrStr.Format("%s\nFile Name = %s", errStr, szFilename);
int iResponse = AfxMessageBox(szErrStr, MB_YESNO|MB_ICONERROR);
}

Hope this helps!

Valerie Bradley
http://www.synthcom.com/~val
val@synthcom.com

Michael Decker
April 16th, 1999, 12:36 PM
Very good, you still may want to add constant strings to the string table. Especially for internationalization.
It might look like: "%1\nFilename: %2"