Presenting NSLocalizedFailureReasonErrorKey

  • Method -presentError: presents a modal dialog showing an NSError.  It
    shows the domain and the code, but not the
    NSLocalizedFailureReasonErrorKey from the userInfo dictionary.  Why
    not?  I must be doing something wrong.  Is not
    NSLocalizedFailureReasonErrorKey far more informative to the user
    than the domain or code number?

    Jerry Krinock

    TEST CODE:

    NSDictionary *userInfo ;
    userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
        @"That dog won't hunt.", NSLocalizedFailureReasonErrorKey,
        nil] ;

    NSError* error ;
    error = [NSError errorWithDomain:@"com.MyCompany.ErrorDomain"
                                code:123
                            userInfo:userInfo] ;

    [[NSApplication sharedApplication] presentError:error] ;

    EXPECTED RESULT:
    A modal dialog saying something like:
      "That dog won't hunt.  com.MyCompany.ErrorDomain error #123"

    ACTUAL RESULT:
    A modal dialog saying only:
      "com.MyCompany.ErrorDomain error #123"
  • Look at the Error Handling programming guide. In the section on The
    User Info Dictionary, it has this to say about the failure reason:

    "A brief sentence that explains the reason why the error occurred. It
    is typically part of the error description. Methods such as
    presentError: do not automatically display the failure reason because
    it is already included in the error description. The failure reason
    is for clients that only want to display the reason for the failure."

    So, unless you want to write your own error displaying routine, you
    should stick the failure reason in the NSLocalizedDescriptionKey.

    Cheers,
    Hank

    On Oct 1, 2007, at 2:15 PM, Jerry Krinock wrote:

    > Method -presentError: presents a modal dialog showing an NSError.
    > It shows the domain and the code, but not the
    > NSLocalizedFailureReasonErrorKey from the userInfo dictionary.  Why
    > not?  I must be doing something wrong.  Is not
    > NSLocalizedFailureReasonErrorKey far more informative to the user
    > than the domain or code number?
    >
    > Jerry Krinock
    >
    > TEST CODE:
    >
    > NSDictionary *userInfo ;
    > userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
    > @"That dog won't hunt.", NSLocalizedFailureReasonErrorKey,
    > nil] ;
    >
    > NSError* error ;
    > error = [NSError errorWithDomain:@"com.MyCompany.ErrorDomain"
    > code:123
    > userInfo:userInfo] ;
    >
    > [[NSApplication sharedApplication] presentError:error] ;
    >
    > EXPECTED RESULT:
    > A modal dialog saying something like:
    > "That dog won't hunt.  com.MyCompany.ErrorDomain error #123"
    >
    > ACTUAL RESULT:
    > A modal dialog saying only:
    > "com.MyCompany.ErrorDomain error #123"
    >

    Hank Heijink
    <hank.list...>
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today