gpt4 book ai didi

iphone - CADisplayLink 吞下异常

转载 作者:可可西里 更新时间:2023-11-01 05:58:59 25 4
gpt4 key购买 nike

我注意到在使用 CADisplayLink 时,异常会被吞没:

CADisplayLink *aDisplayLink = [[UIScreen mainScreen] displayLinkWithTarget:self selector:@selector(doIt)];
[aDisplayLink setFrameInterval:100];
[aDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

...

- (void) doIt
{
NSLog(@"Before");

// Force an exception
NSLog(@"%@", [[NSArray array] objectAtIndex:1]);

NSLog(@"After");
}

运行此代码会产生以下输出:

2011-04-11 18:30:36.001 TestFrameLink[10534:207] Before
2011-04-11 18:30:37.666 TestFrameLink[10534:207] Before
2011-04-11 18:30:39.333 TestFrameLink[10534:207] Before

这是 CADisplayLink 的正确行为吗?有什么方法可以让它在出现异常时中止程序,而不是展开堆栈并假装什么都没发生?

最佳答案

我怀疑 CoreAnimation 的 C++ 内部结构(如回溯中所证明)是导致您注意到的异常吞噬的原因(或者更确切地说,我不认为 N​​STimer 吞噬异常); CoreAnimation 回调(从 +[UIView setAnimationDidFinishSelector:] 或什至 -viewDidAppear: 调用)似乎做同样的事情,除了我认为它们打印了一条日志消息。我不确定为什么 Apple 选择异常吞噬而不是异常处理;哦好吧。

据我所知,完成您所要求的唯一方法是,

@try
{
...
}
@catch(...)
{
abort();
}

没什么帮助,我知道。另外两件可能有帮助的事情:

关于iphone - CADisplayLink 吞下异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5629478/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com