如何在iPhone应用程序中执行应用程序级异常处理 [英] How to do a application level exception handling in iPhone application

查看:100
本文介绍了如何在iPhone应用程序中执行应用程序级异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个应用程序来进行一些图像处理。如果有些事情出错,应用程序崩溃。我想避免这种情况。当任何异常发生在应用程序的任何阶段时,我想处理它并给用户一个友好的消息。在C#中,Windows窗体应用程序可以做到这一点,但对于iPhone来说,我是新的,因此不了解任何方法。

I am working on an application to do some image processing. If some thing goes wrong the application crashes. I want to avoid such scenarios. When ever any exception occurs in any stage of the application, I want to handle it and give the user a friendly message. In C#, windows form application this can be done, but for iPhone I am new and thus do not know any way of achieving it.

任何身体都可以帮助我。

Can any body help me in this.

谢谢

Ashwani

推荐答案

您可以实现符合此签名的未捕获异常处理程序:

You can implement an uncaught exception handler conforming to this signature:

typedef volatile void NSUncaughtExceptionHandler(NSException *exception);

通过调用 NSSetUncaughtExceptionHandler 函数。从那里你可以弹出你想通知用户应用程序正在关闭的任何UI(我们实际上收集一个堆栈跟踪并调用一个mailto:url将崩溃发送给我们 - 这是已经过时了,给定iTunes 8.2的自动崩溃报告)。

by calling the NSSetUncaughtExceptionHandler function. From there you can popup whatever UI you want to inform the user that the app is shutting down (we actually collect a stack trace and invoke a mailto: url to have the crash sent to us--this is obsolete given iTunes 8.2's automatic crash reporting).

编辑:
要清楚,您的应用程序将在您的处理程序完成后终止,没有办法。我不知道为什么你会希望你的应用程序在这一点上继续执行,因为它很可能处于不一致的状态。只是让它崩溃而不是潜在的破坏数据或更糟糕的情况总是更好。从苹果文档:

To be clear, your app will be terminated after your handler is finished, there's no way around it. I'm not sure why you would want your app to continue execution at this point, given that it's very likely in an inconsistent state. It's almost always better to just let it crash than to potentially corrupt data or worse. From the Apple docs:


设置顶级错误处理
函数,您可以执行
last-程序
终止之前的分钟记录。

这篇关于如何在iPhone应用程序中执行应用程序级异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆