I'v noticed that when my app crashes on the main thread , while running on device, the program stops and I get the call stack on XCode so I can see exactly where/why the crash happend.
However, when the crash happens on a secondary thread, the main thread (gui) continue to run normally and I only get message on the console about the crash, without the entire call stack.
To verify it I called a method which doesn't exist, once on the main thread on once on a secondary thread, and indeed when the secondary thread crash I only see a message in the console about the "unrecognized selector".
Is there a way to make the secondary thread crash the app and showing the full stack as well ? It would be very useful for debug purpos开发者_JAVA技巧es.
Thanks
Turned out the reason I didn't see the crash was that I had try&catch statements...gotta watch out for them.
You should put a try...catch around the second thread's code and just dump the full exception description in the catch.
Although unfamiliar with the internals of the iPhone for this, remember that the main thread is just a loop that is running various methods. For any code that the system executes on the main loop, it most likely executes that code in a try...catch so it can log the problem, and, potentially, exit the app gracefully.
精彩评论