当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Draw on screen with CoreGraphics when hit NSSetUncaughtExceptionHandler

问题描述:

I'm trying to draw something simple on screen when NSSetUncaughtExceptionHandler gets called but nothings happen.

Is there any other way to catch an exception and quickly draw something on screen?

NSSetUncaughtExceptionHandler(&exceptionHandler);

void exceptionHandler(NSException *exception)

{

UIBezierPath *path = [UIBezierPath bezierPath];

[path moveToPoint:CGPointMake(10.0, 10.0)];

[path moveToPoint:CGPointMake(10.0, 10.0)];

[path addLineToPoint:CGPointMake(10.0, 450.0)];

[path addLineToPoint:CGPointMake(310.0, 450.0)];

[path addLineToPoint:CGPointMake(310.0, 10.0)];

[path addLineToPoint:CGPointMake(10.0, 10.0)];

CAShapeLayer *shapeLayer = [CAShapeLayer layer];

shapeLayer.path = [path CGPath];

shapeLayer.strokeColor = [[UIColor blueColor] CGColor];

shapeLayer.lineWidth = 3.0;

shapeLayer.fillColor = [[UIColor clearColor] CGColor];

[APP_DELEGATE_WINDOW.rootViewController.view.layer addSublayer:shapeLayer];

[APP_DELEGATE_WINDOW makeKeyAndVisible];

}

网友答案:

I'm not sure that the NSSetUncaughtExceptionHandler is a good place to draw stuff on the screen.

Sets the top-level error-handling function where you can perform last-minute logging before the program terminates.

Most crash reporters carefully log the trace and try not to "touch" anything besides.

If you really want to draw something (what?) you should maybe catch a particular exception first. Just not any uncaught exception.

网友答案:

I think Rivera is right, about NSSetUncaughtExceptionHandler. And maybe you need to write: [path fill];

P.S : I'm sorry that i write here, comments disabled, small reputation...

网友答案:

Like Rivera said, you won't be able to rescue the application at this stage, but if you really needed to draw something here, you could probably launch another process (which you would have to design) just to show this image.

分享给朋友:
您可能感兴趣的文章:
随机阅读: