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] Be开发者_如何转开发fore
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?
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,
@try
{
...
}
@catch(...)
{
abort();
}
Not much help, I know. Two other things that might help:
- Breakpoint objc_exception_throw
- http://bugreport.apple.com/
精彩评论