加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – CADisplayLink吞下异常

发布时间:2020-12-14 17:27:03 所属栏目:百科 来源:网络整理
导读:我注意到在使用CADisplayLink时,异常只会被吞下: CADisplayLink *aDisplayLink = [[UIScreen mainScreen] displayLinkWithTarget:self selector:@selector(doIt)];[aDisplayLink setFrameInterval:100];[aDisplayLink addToRunLoop:[NSRunLoop currentRunLo
我注意到在使用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内脏(在回溯中证明)是你注意到的异常吞咽的原因(或者更确切地说,我不认为NSTimer会吞下异常); CoreAnimation回调(从[UIView setAnimationDidFinishSelector:]调用,或者甚至可能是-viewDidAppear:动画时)似乎做同样的事情,除了我认为他们打印了一条日志消息.我不确定为什么Apple会选择异常吞咽,而不是异常处理;那好吧.

就我所知,做你所要求的唯一方法就是

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

我知道,帮助不大.另外两件可能有用的事情:

>断点objc_exception_throw
> http://bugreport.apple.com/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读