iOS - 在异常处理程序中发送webrequest失败

时间:2013-01-11 00:00:50

标签: ios objective-c exception-handling try-catch http-request

我的应用程序中抛出异常,我正在尝试处理它。目的是打电话给我们的服务器,这是不成功的。我已经在try / catch语句中隔离了服务器调用,以查看是否抛出了另一个异常,但是从我的日志中可以看出,没有抛出其他异常。是否可以从异常处理程序发送Web请求,或者由于某种原因导致进程中断?

void uncaughtExceptionHandler(NSException *exception) {
    [Flurry logError:@"Uncaught" message:@"Crash!" exception:exception];
    NSLog(@"Exception: %@", exception);
    NSArray *stack = [exception callStackReturnAddresses];
    NSLog(@"Stack trace: %@", stack);
    NSString *stackTrace = [stack description];
    @try {
        NSString *domain = @"blabla.mydomain.com";
        NSURL *url2 = [NSURL URLWithString: [NSString stringWithFormat: @"http://%@/error/SendExceptionDetailsToStaff", domain]];
        ASIFormDataRequest *request2 = [ASIFormDataRequest requestWithURL:url2];
        [request2 setPostValue: stackTrace forKey:@"stackTrace"];
        [request2 setPostValue: [[UIDevice currentDevice] model] forKey:@"device"];
        [request2 setPostValue: [[UIDevice currentDevice] systemVersion] forKey:@"osVersion"];
        [request2 startAsynchronous];     
    }
    @catch (NSException * e) {
        NSLog(@" Request Exception: %@", e);
    }
    NSLog(@"yooooo"); 
}


log:
2013-01-10 15:16:20.761 myApp[4653:c07] Stack trace: (0x28fa012 0x1b6ce7e 0x2982fb1 0x8c601 0xc1f753 0xc1fa7b 0xc2d590 0xc355bd 0xc35eab 0xc35fc9 0xc36055 0xd3b3ab 0xb8c92d 0x1b806b0 0x7409fc0 0x73fe33c 0x73fe150 0x737c0bc 0x737d227 0x737d8e2 0x28c2afe 0x28c2a3d 0x28a07c2 0x289ff44 0x289fe1b 0x2b327e3 0x2b32668 0xb3c65c 0x216d 0x20a5)
2013-01-10 15:16:20.761 myApp[4653:c07] yooooo

2 个答案:

答案 0 :(得分:1)

结束解决我自己的问题。问题是异步Web请求在完成之前会被中断。使它同步并保持在同一个线程上解决了这个问题。

[request2 startSynchronous];

答案 1 :(得分:0)

尝试设置异常断点(此处的说明:http://developer.apple.com/library/ios/#recipes/xcode_help-breakpoint_navigator/articles/adding_an_exception_breakpoint.html) - 您应该获得更具描述性的调试消息。