MonoTouch 堆栈跟踪不详细
我正在尝试为我的 MonoTouch 代码实现一个有用的通用异常处理程序。
如果我将处理程序附加到 AppDomain.CurrentDomain.UnhandledException ,则根本不存在堆栈跟踪,即 .StackTrace 属性为 null 或为空。
如果我将 UIApplication.Main(args)
调用包装在 try {} catch {}
中,堆栈跟踪不包含任何有用的信息:
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00000] in <filename unknown>:0
at MonoTouch.UIKit.UIApplication.Main (System.String[] args) [0x00000] in <filename unknown>:0
at MyNamespace.MyProduct.MyProject.Application.Main (System.String[] args) [0x00000] in <filename unknown>:0
即它不会比我捕获异常的 Main() 方法更深的地方。
我有什么想法可以在堆栈跟踪中获取一些更有用的信息,或者它是否完全通过 AOT 编译进行优化? (堆栈跟踪在调试模式下与预期一致。)
I am trying to implement a useful general exception handler for my MonoTouch code.
If I attach a handler to AppDomain.CurrentDomain.UnhandledException
, there is no stack trace present at all, i.e. the .StackTrace property is null or empty.
If I wrap my UIApplication.Main(args)
call in try {} catch {}
, the stack trace doesn't contain any useful information:
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00000] in <filename unknown>:0
at MonoTouch.UIKit.UIApplication.Main (System.String[] args) [0x00000] in <filename unknown>:0
at MyNamespace.MyProduct.MyProject.Application.Main (System.String[] args) [0x00000] in <filename unknown>:0
i.e. it doesn't go any deeper than the Main() method where I caught the exception.
Any ideas how I can get some more useful information in the stack trace at all, or is it all optimised away completely by the AOT compilation? (The stack trace is as expected in debug mode.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 --debug 命令行选项或在 MonoDevelop 中选择配置“Debug|iPhone”。
请记住,此选项将导致执行速度变慢,但您将在异常等情况下获得行号。
Use the --debug command line option or select configuration "Debug|iPhone" in MonoDevelop.
Remember that this option will result in slower execution, but you will get line numbers in exceptions etc.
您将无法获取发布代码中的行号或文件名。该信息已被删除。但是,您仍然应该能够在代码中获取完整的堆栈跟踪,以至少查看类/调用层次结构。
我猜您一定在事后调查这一点,因为您无法调试或捕获发布版本上的运行异常。我倾向于将异常记录到日志文件中以便稍后检查。
此过程从以下代码开始:
您还可以创建带有异常的 StackTrace 对象。我会开始在那里玩耍。请记住,在许多情况下,如果错误发生在 iOS 部分的深处,您将无法获得堆栈跟踪,因为 Mono 不会暴露于该数据。仅发生到主方法的异常或崩溃通常表明存在较低级别的问题。
You won't be able to get line numbers or file names in release code. That information is stripped out. However, you should still be able to get the full stack trace into your code to at least see the class/call hierarchy.
I'm guessing you must be looking into this after the fact though, seeing as you can't debug or catch running exceptions on a release build. What I tend to do is log my exceptions to a log file to check later on.
This process starts with the following code:
You can also create StackTrace objects with an exception too. I would start playing around there. Keep in mind that in many situations, you can't get a stack trace if the error occurs deep within the iOS portion of things as Mono isn't exposed to that data. An exception or crash that occurs that only goes up to the main method usually indicates a lower level issue.