CADisplayLink 吞掉异常
我注意到,使用 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 的正确行为吗? 有没有什么方法可以让它在异常出现时中止程序,而不是展开堆栈并假装什么也没发生?
I've noticed that when using CADisplayLink, exceptions just get swallowed:
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");
}
Running this code produces the following output:
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
Is this the correct behavior for CADisplayLink?
Is there any way to make it abort the program when an exception bubbles up rather than unwind the stack and pretend nothing happened?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑 CoreAnimation 的 C++ 内部结构(如回溯中所证明的)是造成您注意到的异常吞没的原因(或者更确切地说,我不认为 NSTimer 吞没异常); CoreAnimation 回调(在动画时从
+[UIView setAnimationDidFinishSelector:]
甚至可能-viewDidAppear:
调用)似乎做了同样的事情,除了我认为它们打印了一条日志消息。我不知道为什么苹果选择异常吞咽而不是异常处理;那好吧。据我所知,做你所要求的事情的唯一方法是,
没有太大帮助,我知道。另外两件事可能会有所帮助:
I suspect CoreAnimation's C++ innards (as evidenced in backtraces) are responsible for the exception-swallowing you've noticed (or rather, I don't think NSTimer swallows exceptions); CoreAnimation callbacks (called from
+[UIView setAnimationDidFinishSelector:]
or probably even-viewDidAppear:
when animated) seem to do the same thing, except I think they printed a log message. I'm not sure why Apple's chosen exception-swallowing in preference to exception handling; oh well.The only way to do what you're asking is, as far as I know,
Not much help, I know. Two other things that might help: