CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Errror handling

  1. #1
    Join Date
    Apr 1999
    Posts
    121

    Errror handling

    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



  2. #2
    Join Date
    Apr 1999
    Posts
    90

    Re: Errror handling

    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...




  3. #3
    Join Date
    Apr 1999
    Location
    Portland, OR, USA
    Posts
    18

    Re: Errror handling

    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
    [email protected]

  4. #4
    Join Date
    Apr 1999
    Posts
    90

    Re: Errror handling

    Very good, you still may want to add constant strings to the string table. Especially for internationalization.
    It might look like: "%1\nFilename: %2"


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

Featured