View Full Version : Getting function name from Exception
xmax
May 18, 2009, 04:02 AM
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.
robbieduncan
May 18, 2009, 04:06 AM
Erm, first of all which language are we talking about here?
xmax
May 18, 2009, 06:35 AM
Sorry,
I am talking about objective C , in Cocoa application.
Thanks.
robbieduncan
May 18, 2009, 06:40 AM
As you can see in the NSException (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSException_Class/Reference/Reference.html#//apple_ref/doc/uid/20000061) 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 (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSException_Class/Reference/Reference.html#//apple_ref/occ/instm/NSException/callStackReturnAddresses) 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 (http://developer.apple.com/documentation/Cocoa/Conceptual/Exceptions/Tasks/ControllingAppResponse.html#//apple_ref/doc/uid/20000473).
So, in short, read the documentation (in this case the obviously named Exception Programming Topics for Cocoa (http://developer.apple.com/documentation/Cocoa/Conceptual/Exceptions/Exceptions.html#//apple_ref/doc/uid/10000012)). The answer is almost always there.
xmax
May 18, 2009, 08:12 AM
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.
robbieduncan
May 18, 2009, 08:16 AM
Just capture the output of the NSTask. I'm not about to Google that for you.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.