OSStatus, printing the actual reason for the fail?

Discussion in 'Mac Programming' started by subsonix, May 12, 2010.

  1. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #1
    Hi,

    I wonder if anyone know of a function that will take my OSStatus error code and return a string that makes more sense.

    I have found a apple utility but, it's c++ and my whole program is in c. I'm not rewriting it to compile in c++ just to get a comprehensible string from this obscure number.

    Surely there must be a function just for this in Carbon or CoreFoundation right?
     
  2. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #2
    I'm not sure without looking, but why not just rewrite the c++ code from Apple?

    EDIT: after a quick search are neither of these useful?
    const char* GetMacOSStatusErrorString(OSStatus err);
    const char* GetMacOSStatusCommentString(OSStatus err);

    in CoreServices/CarbonCore/Debugging.h
     
  3. subsonix thread starter macrumors 68040

    Joined:
    Feb 2, 2008
    #3
    Thanks for that. It seems to work, but the strings it returns are unfortunately empty. This is for core audio, and perhaps the empty strings are the reason for the existence of the error handling utility header. I might have to do as you first suggested and try to get some sense from the header file.
     
  4. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #4
    Do you think you will get a comprehensible string out of an OSStatus anyway? The best you can expect is a sequence of English words that leaves your user just as baffled as an obscure number. The obscure number, on the other hand, has a better chance to be reported back to you correctly, giving you a chance to fix the problem.
     
  5. subsonix thread starter macrumors 68040

    Joined:
    Feb 2, 2008
    #5
    I don't know really, but the purpose here is to get some insight (for me) why a function call returns err. I'm doing something wrong obviously but, was hoping for something more than what I get with my own macro, that does nothing more than exit the application and tell me which function returned the error code.
     
  6. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #6
    What are your error numbers? Can you find them in MacErrors.h?
     
  7. subsonix thread starter macrumors 68040

    Joined:
    Feb 2, 2008
    #7
    Thanks. I had a look at MacErrors.h but did not find it there. I noticed that all numbers where negative and a great deal smaller than what I get if I print my number however. I'm not sure if there is a corresponding string or if apples macro simply terminates and does some house keeping with allocated resources, closing files etc. then exits. Never mind though, I have to take a closer look at the documentation, I'm sure I'm doing something wrong when I make my function call. Thanks for the help and suggestions.
     
  8. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #8
    Please be specific.

    Post examples of the error numbers. Post the exact names of the functions returning those errors. Exactly which Apple macro are you talking about?

    You said you were working with Core Audio. It has a number of error-codes that will appear to be obscure and discontiguous in any numerical sense. These are all defined as 4-char-constants in AudioHardware.h. For example:
    Code:
        kAudioHardwareBadObjectError                = '!obj',
        kAudioHardwareBadDeviceError                = '!dev',
        kAudioHardwareBadStreamError                = '!str',
        kAudioHardwareUnsupportedOperationError     = 'unop',
        kAudioDeviceUnsupportedFormatError          = '!dat',
        kAudioDevicePermissionsError                = '!hog'
    
    That file also has this comment:
    AFAIK, some of those other codes are also formed as 4-char-constants.
     
  9. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #9
    You could try CFError. Use CFErrorCreate(), passing in the domain kCFErrorDomainOSStatus and your OSStatus value. Then see if CFErrorCopyDescription() returns anything useful. However, I would be surprised if that worked with Core Audio values but you could give it a shot.
     
  10. subsonix thread starter macrumors 68040

    Joined:
    Feb 2, 2008
    #10
    Thanks kainjow. That's pretty clever, tried it but as you predicted the string is empty in this case as well. I will look over the code to see what is wrong my self.

    chown33, I guess I was looking for a quick answer, just to cover if there was a function to do what I had in mind here. But, the macro I was referring to is XThrowIfError in CAXException.h. The error code in my case is: 1768846202 which comes down to 'zsni' if interpreted as 4 chars.

    Thanks.
     
  11. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #11
    In <AudioToolbox/AudioConverter.h>

    Code:
    kAudioConverterErr_InvalidInputSize = 'insz',
     
  12. jpyc7 macrumors 6502

    Joined:
    Mar 8, 2009
    Location:
    Denver, CO
    #12
    Cute. :) Little endianess strikes again.
     
  13. subsonix thread starter macrumors 68040

    Joined:
    Feb 2, 2008
    #13
    Thanks, that's excellent. It restricts the possibilities quite a bit!
     
  14. subsonix thread starter macrumors 68040

    Joined:
    Feb 2, 2008
    #14
    Yeah lol. I just did this with out thinking to much:

    Code:
            while( i < 4 )
                    printf("%c", *(((char*)&error)+i++) );
    
     
  15. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #15
    What does the debugger say when you use "display as OSType"?
     
  16. subsonix thread starter macrumors 68040

    Joined:
    Feb 2, 2008
    #16
    Gnasher, that seems like a good idea. I have not used that feature in Xcode and looking at it all the options are grey, except "Use Data Formatters" in the variables view menu. Any Idea how I can access them?
     

Share This Page