如何找出 Xcode 调试器(适用于 iPhone)中抛出的异常?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/384775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:26:39  来源:igfitidea点击:

How do I find out what exception was thrown in the Xcode debugger (for iPhone)?

iphonexcodedebuggingexception

提问by Daryl Spitzer

I'm learning iPhone programming from Erica Sadun's The iPhone Developer's Cookbook. When I run the app I created by following the steps in the Temperature Conversion Example starting on page 81 in the simulator, it terminates due to an uncaught exception. (See http://groups.google.com/group/iphonesdk/browse_frm/thread/6f44a90fdb8da28a?hl=enfor the question I posted to the iPhoneSDK Google Group.)

我正在从 Erica Sadun 的 The iPhone Developer's Cookbook 学习 iPhone 编程。当我按照模拟器中从第 81 页开始的温度转换示例中的步骤运行我创建的应用程序时,它由于未捕获的异常而终止。(有关我发布到 iPhoneSDK Google 群组的问题,请参阅http://groups.google.com/group/iphonesdk/browse_frm/thread/6f44a90fdb8da28a?hl=en。)

The exception is thrown after calling UIApplicationMain() from my main(). If I look through the stack trace in the debugger, all I see is (of course) assembly. How do I find out what kind of exception was thrown?

从我的 main() 调用 UIApplicationMain() 后抛出异常。如果我查看调试器中的堆栈跟踪,我看到的只是(当然)程序集。我如何找出抛出了什么样的异常?

Update:
Learning the details of the exception from the Debugger Console was enough to help me solve the problem. (See http://groups.google.com/group/iphonesdk/browse_frm/thread/6f44a90fdb8da28a?hl=en.) I verified that I could set a symbolic breakpoint on objc_exception_throw, but I didn't look to see if the backtrace from there would have been helpful.

更新
从调试器控制台了解异常的详细信息足以帮助我解决问题。(请参阅http://groups.google.com/group/iphonesdk/browse_frm/thread/6f44a90fdb8da28a?hl=en。)我确认我可以在 上设置符号断点objc_exception_throw,但我没有查看是否来自会有帮助。

回答by Lily Ballard

Put a breakpoint at objc_exception_throwand run your app via Debug instead of Run

将断点放置在objc_exception_throw并通过调试而不是运行运行您的应用程序

To clarify, what you're actually seeing when you get an exception without the breakpoint is the same stack trace always - it's the uncaught exception handler. The type of exception is logged to the Run console, but if you want to see a backtrace for where the exception was raised, that's what the breakpoint is for.

澄清一下,当您在没有断点的情况下获得异常时,您实际看到的始终是相同的堆栈跟踪 - 它是未捕获的异常处理程序。异常类型记录到运行控制台,但如果您想查看引发异常的位置的回溯,这就是断点的用途。

回答by samwize

In the new Xcode (at least starting from v4.5), you can catch all exceptions easily by doing this:

在新的 Xcode(至少从 v4.5 开始)中,您可以通过执行以下操作轻松捕获所有异常:

  1. Bring up breakpoint navigator (?6)
  2. Click + on the bottom left
  3. Add Exception Breakpoint
  1. 调出断点导航器 (?6)
  2. 点击左下角的+
  3. 添加异常断点

I think the above is the same as a breakpoint on objc_exception_throw. http://samwize.com/2012/09/26/xcode-4-dot-5-tips-and-tricks/

我认为上面的内容与 上的断点相同objc_exception_throwhttp://samwize.com/2012/09/26/xcode-4-dot-5-tips-and-tricks/

回答by Dale

http://ijoshsmith.com/2011/11/28/debugging-exceptions-in-xcode-4-2/

http://ijoshsmith.com/2011/11/28/debugging-exceptions-in-xcode-4-2/

Same as samewize's solution, but also shows how to make this breakpoint show up by default in all your projects (right click on breakpoint, Move Breakpoint To, User).

与 samewize 的解决方案相同,但还展示了如何在所有项目中默认显示此断点(右键单击断点,将断点移至用户)。

回答by samwize

As Kevin answered, you will find more helpful debugging info by setting a breakpoint at objc_exception_throw.

正如凯文所回答的那样,通过在objc_exception_throw.

If you are using Xcode 4.2, you can add this symbolic breakpoint by going to Breakpoint Navigator > Click on the add icon on the bottom left > Add symbolic breakpoint > Enter objc_exception_throwfor Symbol > Done.

如果您使用的是 Xcode 4.2,则可以通过转到 Breakpoint Navigator > 单击左下角的添加图标 > 添加符号断点 > 输入objc_exception_throw符号 > 完成来添加此符号断点。