Getting function name from Exception

Discussion in 'Mac Programming' started by xmax, May 18, 2009.

  1. xmax macrumors member

    Joined:
    Jul 3, 2008
    #1
    Hello,

    I want to have function name and class name on which Exception has been occurred.

    is it possible to get class name and function name from exception ?
    if yes , then how can i get it ?


    Thanks.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Erm, first of all which language are we talking about here?
     
  3. xmax thread starter macrumors member

    Joined:
    Jul 3, 2008
    #3
    Sorry,

    I am talking about objective C , in Cocoa application.


    Thanks.
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    As you can see in the NSException class reference there is no direct way to do this. If the object raising the exception chooses to it can include this information in the userInfo dictionary.

    You can use the stackReturnAddresses to work out this sort of information, although this would take some work. Fortunately this work has been done for you as described in the documentation.

    So, in short, read the documentation (in this case the obviously named Exception Programming Topics for Cocoa). The answer is almost always there.
     
  5. xmax thread starter macrumors member

    Joined:
    Jul 3, 2008
    #5
    Thanks for your reply. it really helped me lot.
    I printed stack trace and it is giving me class file and its line number.
    but i want all stack trace printed in string value.

    is it possible to get NSString value for printed stack ?


    Thanks.
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    Just capture the output of the NSTask. I'm not about to Google that for you.
     

Share This Page