@catch块在调试模式下不捕获异常

时间:2013-10-23 08:55:46

标签: ios iphone objective-c cocoa-touch nsexception

进一步提出我的问题,这里提到的解决方案:https://stackoverflow.com/a/19153387/260665解决问题的唯一方法是实现@try-@catch块并通过清除线程的结果来优雅地处理异常例外。

这是我的try-catch块:

    // These operations are meant to calculate statistics for the Task objects, now when the statistics are being calculated there are possibilities that the main thread might delete the ManagedObject from it's MOC and write to the store. Now this means that ManagedObjects here may not have an equivalent record back in the store to refer!
    // So, when the already faulted objects try to access it's properties, NSObjectInaccessibleException arises. For more details check the SO post: https://stackoverflow.com/questions/18828164/coredata-object-fault-in-independent-managedobjectcontext-vs-changes-in-persiste
    // Hence catching the exception and returning back no results is the best approach as of now!
    @try
    {
        CSStatistics *theStats = [self statisticsOperationFromDate:self.dateRange.fromDate
                                                            toDate:self.dateRange.toDate];
        [self setOutStatistics:theStats];

        if ([(NSObject*)[self resultDelegate] respondsToSelector:@selector(statisticsOperationCompletedWithOperation:)])
        {
            [(NSObject*)[self resultDelegate] performSelectorOnMainThread:@selector(statisticsOperationCompletedWithOperation:)
                                                               withObject:self
                                                            waitUntilDone:NO];
        }
    }
    @catch (NSException *exception)
    {
        DEBUGLog(@"Most probably a NSObjectInaccessibleException exception! - %@", exception);
        [self setOutStatistics:nil];    // We would not like to give out erroneous reports! Mind it!
    }
    @finally
    {

    }

奇怪的事情发生了,我的try-catch块在分发构建中非常有效,因为应用程序在调试和发布版本中崩溃。显然,引发时的异常是在某处处理的,它不会传递给@catch块,而是被消耗掉。我无法弄清楚Xcode在哪里没有提供相同的细节。

这是调试模式中的日志:

2013-10-23 14:33:07.293 CATSXT[64267:650b] *** Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0x1912fc00 <x-coredata://6E14A109-8A14-4369-BBC5-468D790A8D9E/CSTask/p7562>''
*** First throw call stack:
(0x33af012 0x2d25e7e 0x2a4ba48 0x2a4b3f7 0x2a4b031 0x2a4aea6 0x10eb42e2 0x5e02d 0x242e00b 0x2a86fc4 0x5cc58 0x244c247 0x5d492 0x244c205 0x5d492 0x246d23c 0x2440c70 0x15c075 0x15caac 0x15c6dd 0x244e453 0x244e164 0x24daa31 0x601253f 0x6024014 0x60152e8 0x6015450 0x949b0e72 0x94998d2a)
libc++abi.dylib: terminate called throwing an exception

一些谷歌搜索向我展示了'All Exceptions'断点导致了这种行为,但我也禁用了该断点。现在我仍然无法弄清楚为什么在调试和发布版本中没有执行@catch块,但它在分发版本中运行得非常好。这不会给生产应用程序的用户带来麻烦,但它肯定会损害开发过程。

任何线索都会非常感激。

0 个答案:

没有答案