I use NSSetUncaughtExceptionHandler
to print the stack trace to local file in iPhone, which will be sent to our server next time the app launches. Then I can examine the exception data and fix the bug.
In some crashes I have the module name and the function that threw the exception, these are easy.
But mostly I have something like this:
"4 libc++abi.dylib 0x35bba3c5 _ZL19safe_handler_callerPFvvE + 76",
"5 libc++abi.dylib 0x35bba451 _ZdlPv + 0",
"6 libc++abi.dylib 0x35bbb825 __cxa_current_exception_type + 0",
"7 libobjc.A.dylib 0x37bab2a9 objc_exception_rethrow + 12",
"8 CoreFoundation 0x3575a50d CFRunLoopRunSpecific + 404"
and for example the reason:
*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array
but I have dozens of arrays in my app, so I need help to find the specific line that threw the exception, using the data I get from the stack trace.
Does anyone know a good article/tutorial from Apple or other, where I can learn to decode the numbers in the stack trace to find the problematic line in the source code. Thanks in advance!
I strongly recommend enabling Exception Breakpoint in Xcode. It will stop execution of your code on the exact line which crashes your application. So you do not need to worry about which of the array cause of the crash. *** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array
Adding exception breakpoint
I don't know how to get line numbers from stack traces (yet), but at some points in my code where I want to get line number printed I used the have the following code fragment:
NSLog(@"%s line=%d", __func__, __LINE__);
which will give the following output:
2013-04-01 00:16:46.393 MyApp[847:c07] -[AppDelegate application:didFinishLaunchingWithOptions:] line=29
If you're familiar with the Log4J framework I'ld suggest to take a look at the Lumberjack framework which proves to be very helpful for me in various projects.
https://github.com/robbiehanson/CocoaLumberjack
Although this may not directly answer your question, its just meant as a reminder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With