tags:

views:

223

answers:

1

Hello All:

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.

Thanks

Ashwani

+2  A: 

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

typedef volatile void NSUncaughtExceptionHandler(NSException *exception);

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

EDIT: 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:

Sets the top-level error-handling function where you can perform last-minute logging before the program terminates.

drewh
Thanks for your response.But can u please tell me where I have to put this NSUncaughtExceptionHandler? In the appdelegate file or some where else?
Ashwani K
I was able to use the function. I am able to display user a friendly message but application is crashing also. I do not want the application the application to crash. Can this be done??
Ashwani K