开发者

well coded exception handling - @try @catch or without it

I want to know the global mechanism for exception handling.

Like I do have 20 different classes and I want to put try catch in all , then It may be some what time consuming as well as may can create issues.

I found some code like

-(void)ExceptionOccure:(NSException *)exception
{
    NSArray *stack = [exception callStackReturnAddresses];
    NSLog(@"%@", stack);
}

But I am not able to call this method , using

-(void) applicationDidFinishLaunching: (UIApplication *) application
{
     NSSetUncaughtExceptionHandler (&开发者_如何学JAVAamp;ExceptionOccure);
}

I came to know this way but not able to call any exception.

I want to create global mechanism for this exception handling. so that in any class if any exception occurs it will call the above written function and handle the exception as well as can store the stack in the database as I needed.

Can any one suggest me or provide me sample code for handling exception globally..

thanks in advance


your handler function is a C function so you have to implement it like this :

static void uncaughtExceptionHandler(NSException *exception) 
{
   NSArray *stack = [exception callStackReturnAddresses];
   NSLog(@"%@", stack);
}

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜