开发者

Catch error messages globally for an iPhone (Objective C) application

开发者 https://www.devze.com 2023-02-24 12:23 出处:网络
We use try, catch and finally to catch errors in iPhone and handle them in the controller. Can we create a global error handling code such that in case of any error, control passes to that method and

We use try, catch and finally to catch errors in iPhone and handle them in the controller. Can we create a global error handling code such that in case of any error, control passes to that method and we can handle all error related activities like sending message, showing alert etc from that code?

My idea is to have a single point for all error handlin开发者_运维问答g in Objective C (iPhone) apps.

In Coldfusion, we have an onError() method that is invoked if an error occur in the application.


Use NSSetUncaughtExceptionHandler():

NSSetUncaughtExceptionHandler(&handleException);

Then implement your handler as follows:

void handleException (NSException *exception)
{
   // exception handler code
}

Read the documentation for more information.

0

精彩评论

暂无评论...
验证码 换一张
取 消