简体   繁体   中英

iPhone - Crash on a secondary thread doesn't affect main thread

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 purposes.

Thanks

原来我没有看到崩溃的原因是我有try&catch语句...一定要当心它们。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM